[英]Invalid “main” entry for ts-node when running ts-node-dev
I've started a typescript project using yarn, I ran the following commands:我已经使用纱线启动了一个打字稿项目,我运行了以下命令:
yarn init -y
yarn add typescript -D
yarn tsc --init
yarn add ts-node-dev -D
and then I created a script called dev that runs tsnd src/index.ts
, and it gives the following error然后我创建了一个名为 dev 的脚本,它运行tsnd src/index.ts
,它给出了以下错误
yarn run v1.22.4
$ tsnd src/index.ts
internal/modules/cjs/loader.js:329
throw err;
^
Error: Cannot find module 'D:\Documentos\Rafael\Rafael\Softwares\Typescript\base-typescript-project\node_modules\ts-node\dist\index.js'. Please verify that the package.json has a valid "main" entry
at tryPackage (internal/modules/cjs/loader.js:321:19)
at Function.Module._findPath (internal/modules/cjs/loader.js:682:18)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:952:27)
at Function.Module._load (internal/modules/cjs/loader.js:841:27)
at Module.require (internal/modules/cjs/loader.js:1025:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (D:\Documentos\Rafael\Rafael\Softwares\Typescript\base-typescript-project\node_modules\ts-node-dev\lib\compiler.js:26:27)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32) {
code: 'MODULE_NOT_FOUND',
path: 'D:\\Documentos\\Rafael\\Rafael\\Softwares\\Typescript\\base-typescript-project\\node_modules\\ts-node\\package.json',
requestPath: 'ts-node'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
PS D:\Documentos\Rafael\Rafael\Softwares\Typescript\base-typescript-project>
It seems like yarn isn't installing ts-node right, because whenever i run npm i ts-node -D
and then i run yarn dev
it works, does anybody have a clue?似乎 yarn 没有正确安装 ts-node,因为每当我运行npm i ts-node -D
然后我运行yarn dev
它就可以工作,有人知道吗?
Here's my package.json:这是我的 package.json:
{
"name": "base-typescript-project",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"dev": "tsnd src/index.ts"
},
"devDependencies": {
"ts-node-dev": "^1.0.0-pre.61",
"typescript": "^4.0.2"
}
}
我猜我的纱线有问题,所以我运行了yarn clean cache
并创建了一个新项目,现在它可以工作了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.