猿问

在“npm link”和“npm i <repo>”后无法解析模块

我的package.json文件


{

  "name": "ts-logger",

  "main": "dist/index.js",

  "types": "dist/index.d.ts",

  "scripts": {

    "install": "tsc"

  },

  "repository": {

    "type": "git",

    "url": "https://github.com/vkrenta/ts-logger.git"

  },

   "devDependencies": {

    "typescript": "^4.0.2",

    "@types/node": "^14.6.4"

  },

  "dependencies": {}

   ...

}

我的tsconfig.json


{

  "compilerOptions": {

     ...

    "outDir": "./dist",

    "target": "es5",

     ...

    "rootDir": "./"

  },

  "exclude": ["node_modules", "dist"]

}

我试图将它推送到 github 并运行npm link.


在我创建了另一个 npm 项目之后,然后在require('ts-logger')orimport {Logger} from 'ts-logger'之后node .我得到了 npm 无法解析模块的日志


BIG阳
浏览 158回答 1
1回答

红颜莎娜

问题出在package.json - 我只是交换了devDependenciesand dependencies,因为 typescript 是将代码从 git 编译到 dist 文件夹的依赖项。"dependencies": {&nbsp; &nbsp; "typescript": "^4.0.2",&nbsp; &nbsp; "@types/node": "^14.6.4"&nbsp; },&nbsp; "devDependencies": {}更新程序此外,我在包中启动了我的tsconfig.json"target":"es5",但在新项目中启动了"target":"es2015". 所以这意味着你的包目标必须比你项目中的目标更新(或相同)(最好是"target":"ESNext")。
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答