首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LernaJs tsc找不到模块

LernaJs tsc找不到模块
EN

Stack Overflow用户
提问于 2020-04-28 06:16:50
回答 1查看 2.5K关注 0票数 1

我正在使用lerna创建一个完整堆栈的monorepo项目。

在一个子项目中,我得到了Cannot find module '@gepick/database/connect'

我的lerna.json

代码语言:javascript
复制
{
  "packages": ["packages/*", "projects/**"],
  "version": "0.0.0",
  "useWorkspaces": true,
  "npmClient": "yarn"
}

我的gepick/database/package.json:

代码语言:javascript
复制
{
  "name": "@gepick/database",
  "version": "1.0.0",
  "devDependencies": {
    "@types/lodash": "^4.14.149",
    "@types/mongoose": "^5.7.11",
    "source-map-loader": "^0.2.4"
  },
  "dependencies": {
    "lodash": "^4.17.15",
    "mongodb-client-encryption": "^1.0.1",
    "mongoose": "^5.9.9"
  }
}

基于节点的子项目package.json

代码语言:javascript
复制
{
  "name": "scripts-api-football",
  "version": "1.0.0",
  "scripts": {
    "start:collectDayMatches:dev": "tsc-watch --onSuccess \"node -r source-map-support/register build/collectDayMatches.js\"",
    "build": "tsc"
  },
  "devDependencies": {
    "@types/lodash": "^4.14.149",
    "source-map-loader": "^0.2.4",
    "source-map-support": "^0.5.19",
    "tsc-watch": "^4.2.3"
  },
  "dependencies": {
    "@gepick/database": "^1.0.0",
    "axios": "^0.19.2",
    "commander": "^5.0.0",
    "lodash": "^4.17.15",
    "nodemon": "^2.0.3"
  }
}

基于节点的子项目tsconfig.json

代码语言:javascript
复制
{
  "compilerOptions": {
    "target": "es2019",
    "module": "commonjs",
    "moduleResolution": "node",
    "outDir": "dist",
    "strict": true,
    "inlineSourceMap": true,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "strictNullChecks": true,
    "noImplicitThis": true,
    "alwaysStrict": true,
    "allowJs": false,
    "lib": ["es2016", "esnext.asynciterable", "webworker"],
    "types": ["node"],
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strictPropertyInitialization": false,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "forceConsistentCasingInFileNames": true,
    "baseUrl": "./src",
    "paths": {
      "utils/*": ["./utils/*"]
    }
  },
  "exclude": ["tests", "tasks"]
}

主package.json:

代码语言:javascript
复制
{
  "name": "gepick-lerna",
  "version": "1.0.0",
  "private": true,
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "start:front-web": "lerna run start --scope front-web --stream",
    "bootstrap": "lerna bootstrap",
    "build:scripts:api-football": "lerna run build --scope scripts-api-football --stream",
    "start:scripts:api-football:start:collectDayMatches:dev": "lerna run start:collectDayMatches:dev --stream"
  },
  "dependencies": {
    "lerna": "^3.20.2",
    "typescript": "^3.8.3",
    "webpack": "^4.42.1"
  },
  "workspaces": [
    "projects/**",
    "packages/*"
  ],
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^2.27.0",
    "@typescript-eslint/parser": "^2.27.0",
    "eslint": "^6.8.0",
    "eslint-plugin-import": "^2.20.2",
    "eslint-plugin-jsx-a11y": "^6.2.3",
    "eslint-plugin-react": "^7.19.0",
    "eslint-plugin-react-hooks": "^2.5.1"
  }
}

此外,我还尝试将main: "connect.js"添加到@gepick/datebase package.json文件中。但是看起来@gepick/datebase包还没有编译js。也许是问题(tsc不编译库文件)?

EN

回答 1

Stack Overflow用户

发布于 2020-04-29 04:44:14

问题是包没有编译成js。为了运行脚本,我将node更改为ts-node。现在起作用了。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61473807

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档