当我尝试运行tsc-watch时,出现了"找不到模块'typescript/bin/tsc'"的错误。
yarn tsc-watch --noClear -p tsconfig.json
yarn run v1.22.19
$ /Users/jason/Work/VDQ/VDQApp/node_modules/.bin/tsc-watch --noClear -p tsconfig.json
Cannot find module 'typescript/bin/tsc'
Require stack:
- /Users/jason/Work/VDQ/VDQApp/node_modules/tsc-watch/lib/tsc-watch.js
- /Users/jason/Work/VDQ/VDQApp/node_modules/tsc-watch/index.js
这个错误很容易在没有JSBundling/package.json/Yarn设置的情况下重现。
我的package.json文件如下:
{
"name": "app",
"private": "true",
"dependencies": {
"@hotwired/stimulus": "^3.1.0",
"@hotwired/turbo-rails": "^7.2.0",
"@popperjs/core": "^2.11.6",
"bootstrap": "^5.2.2",
"bootstrap-icons": "^1.9.1",
"esbuild": "^0.15.10",
"sass": "^1.55.0",
"tsc": "^2.0.4"
},
"scripts": {
"build": "esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds --public-path=assets",
"build:css": "sass ./app/assets/stylesheets/application.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules",
"failure:js": "rm ./app/assets/builds/application.js && rm ./app/assets/builds/application.js.map",
"compile:typescript": "tsc-watch --noClear -p tsconfig.json --onSuccess \"yarn build\" --onFailure \"yarn failure:js\""
},
"devDependencies": {
"tsc-watch": "^5.0.3"
}
}
我的tsconfig.json文件如下:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"noImplicitAny": true
}
}
yarn global add typescript
。 - Eva