我有一个使用webpack的角度4项目。
我的package.json
包含ngx-mqtt
作为devDependency。据我所知,所有依赖项都应该是webpack的devDependencies。
这导致mqtt.js
包含我用shebang-loader修复的意外#令牌的错误。
现在我收到了错误:
找不到模块:错误:无法解析'mqtt'
我通过将mqtt添加到我的package.json
(我不认为我必须这样做,因为它是ngx-mqtt
的依赖项)来解决这个问题。
这样做会导致:
找不到模块:错误:无法解析'utf-8-validate' 这是websocket-stream的依赖,而websocket-stream又依赖于mqtt
这可不可以吗?我不能自己声明我的库依赖项。
package.json
:
"devDependencies": {
"@angular/animations": "4.2.5",
"@angular/common": "4.2.5",
"@angular/compiler": "4.2.5",
"@angular/compiler-cli": "4.2.5",
"@angular/core": "4.2.5",
"@angular/forms": "4.2.5",
"@angular/http": "4.2.5",
"@angular/platform-browser": "4.2.5",
"@angular/platform-browser-dynamic": "4.2.5",
"@angular/platform-server": "4.2.5",
"@angular/router": "4.2.5",
"@ngtools/webpack": "1.5.0",
"@types/chai": "4.0.1",
"@types/jasmine": "2.5.53",
"@types/text-encoding": "0.0.32",
"@types/webpack-env": "1.13.0",
"@types/node": "^8.0.34",
"angular2-router-loader": "^0.3.5",
"angular2-template-loader": "0.6.2",
"aspnet-prerendering": "^3.0.1",
"aspnet-webpack": "^2.0.1",
"awesome-typescript-loader": "^3.2.3",
"bootstrap": "3.3.7",
"chai": "4.0.2",
"css": "2.2.1",
"css-loader": "0.28.4",
"es6-shim": "0.35.3",
"event-source-polyfill": "0.0.11",
"expose-loader": "^0.7.3",
"extract-text-webpack-plugin": "2.1.2",
"file-loader": "^0.11.2",
"html-loader": "^0.4.5",
"isomorphic-fetch": "2.2.1",
"jasmine-core": "2.6.4",
"jquery": "3.2.1",
"json-loader": "^0.5.7",
"jw-bootstrap-switch-ng2": "^1.0.4",
"karma": "1.7.0",
"karma-chai": "0.1.0",
"karma-chrome-launcher": "2.2.0",
"karma-cli": "1.0.1",
"karma-jasmine": "1.1.0",
"karma-webpack": "2.0.3",
"ngx-mqtt": "1.15.0",
"preboot": "4.5.2",
"raw-loader": "^0.5.1",
"reflect-metadata": "0.1.10",
"rxjs": "5.4.2",
"shebang-loader": "^0.0.1",
"style-loader": "^0.18.2",
"text-encoding": "0.6.4",
"to-string-loader": "^1.1.5",
"typescript": "^2.5.3",
"url-loader": "^0.5.9",
"webpack": "^2.7.0",
"webpack-hot-middleware": "^2.19.1",
"webpack-merge": "4.1.0",
"zone.js": "0.8.12"
}
答案 0 :(得分:0)
你可以在webpackconfig中试试吗
resolve: {
extensions: ['.ts', '.js'],
modules: ['node_modules']
}
您也可以尝试直接将相对路径放入node_modules。