ts-node抛出一个错误:找不到模块,尽管它在tsconfig中

时间:2020-08-29 13:42:41

标签: node.js typescript lerna ts-node

我与lerna有monorepo,我想运行打字稿文件(在scripts文件夹中,而不是软件包中)。

问题是当我运行文件(bar.ts)时-它访问了项目中的某些文件并抛出错误:

Error: Cannot find module '@packages/roles'
Require stack:
- C:\..\prj\packages\pck1\src\foo.ts
- C:\..\prj\packages\pck1\src\index.ts
- C:\..\prj\scripts\bar.ts
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1029:15)
    at Function.Module._load (internal/modules/cjs/loader.js:898:27)
    at Module.require (internal/modules/cjs/loader.js:1089:19)
    at require (internal/modules/cjs/helpers.js:73:18)

我从根项目运行命令:

ts-node scripts/bar

我也有tsconfig.json文件(在根项目中):

{
  "ts-node": {
    "compilerOptions": {
      "target": "es5",
      "module": "commonjs",
      "baseUrl": ".",
      "paths": {
        "@packages/*": ["packages/*/src"]
      }
    }
  },
  "compilerOptions": {
    "noEmit": true,
    "strict": false,
    "jsx": "react",
    "target": "esnext",
    "module": "esnext",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "removeComments": true,
    "rootDir": ".",
    "baseUrl": ".",
    "lib": ["esnext", "dom"],
    "types": ["webpack-env", "node"],
    "paths": {
      "@packages/*": ["packages/*/src"]
    }
  },
  "include": ["packages", "apps", "jest-dom/extend-expect"],
  "exclude": ["node_modules", "dist"]
}

在每个packages/*/src中,我有index.ts暴露了我所需的一切。

不知道我在这里想念的是什么。为什么ts-node无法解析文件?

0 个答案:

没有答案