简体   繁体   中英

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

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?

Here's my 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并创建了一个新项目,现在它可以工作了。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM