我正在尝试构建一个旧项目,但由于出现以下错误而无法执行。使用angular 5.2.9构建项目但遇到了这些错误。有人可以帮忙
我的package.json文件看起来像这样
"dependencies": {
"@angular/core": ">=5.2.9",
"@angular/router": ">=5.2.9",
"ng-packagr": "^3.0.6",
"rxjs-compat": "^6.2.2"
},
"devDependencies": {
"@angular/common": ">=5.2.9",
"@angular/compiler": ">=5.2.9",
"@angular/compiler-cli": "^6.1.0",
"@angular/platform-browser": ">=5.2.9",
"@angular/platform-browser-dynamic": ">=5.2.9",
"@angular/platform-server": ">=5.2.9",
"@types/es6-shim": "^0.31.32",
"@types/jasmine": "^2.5.40",
"@types/selenium-webdriver": "^2.53.39",
"awesome-typescript-loader": "^3.1.2",
"extract-text-webpack-plugin": "^2.1.0",
"jasmine-core": "^2.5.2",
"rxjs": "^6.5.2",
"source-map-loader": "^0.2.0",
"ts-helpers": "^1.1.2",
"tslint": "^4.5.1",
"tslint-loader": "^3.4.3",
"typescript": "^2.2.1",
"webpack": "2.1.0-beta.22",
"webpack-dev-middleware": "^1.10.1",
"webpack-dev-server": "^2.4.1",
"webpack-md5-hash": "0.0.5",
"webpack-merge": "^4.0.0",
"zone.js": ">=0.7.2"
},
正在构建,但是在运行测试用例时会收到这些警告
WARNING in ./~/rxjs-compat/observable/merge.js
Cannot find source file '../src/compat/observable/merge.ts': Error: Can't resolve '../src/compat/observable/merge.ts' in 'D:\MASTERS\master-sales\node_modules\rxjs-compat\observable'
@ ./~/rxjs/observable/merge.js 6:9-48
@ ./~/@angular/core/esm5/core.js
@ ./src/master-sales.service.ts
@ ./src/master-sales.service.spec.ts
@ ./src \.spec\.ts
@ ./spec-bundle.js
WARNING in ./~/rxjs-compat/add/observable/from.js
Cannot find source file '../../src/compat/add/observable/from.ts': Error: Can't resolve '../../src/compat/add/observable/from.ts' in 'D:\MASTERS\master-sales\node_modules\rxjs-compat\add\observable'
@ ./~/rxjs-compat/Rx.js 24:0-32
@ ./~/rxjs/Rx.js
@ ./spec-bundle.js
WARNING in ./~/rxjs-compat/add/observable/fromEvent.js
Cannot find source file '../../src/compat/add/observable/fromEvent.ts': Error: Can't resolve '../../src/compat/add/observable/fromEvent.ts' in 'D:\MASTERS\master-sales\node_modules\rxjs-compat\add\observable'
@ ./~/rxjs-compat/Rx.js 25:0-37
@ ./~/rxjs/Rx.js
@ ./spec-bundle.js
WARNING in ./~/rxjs-compat/add/observable/defer.js
Cannot find source file '../../src/compat/add/observable/defer.ts': Error: Can't resolve '../../src/compat/add/observable/defer.ts' in 'D:\MASTERS\master-sales\node_modules\rxjs-compat\add\observable'
@ ./~/rxjs-compat/Rx.js 21:0-33
@ ./~/rxjs/Rx.js
@ ./spec-bundle.js
答案 0 :(得分:0)
请将"typescript": "3.1.1"
的依赖项添加为:
"dependencies": {
...
"typescript": "3.1.1"
...
}
注意:您可以使用任何其他版本
您的package.json应该如下所示:
"dependencies": {
"@angular/common": "^5.0.0",
"@angular/compiler": "^5.0.0",
"@angular/core": "^5.0.0",
"@angular/forms": "^5.0.0",
"@angular/http": "^5.0.0",
"@angular/platform-browser": "^5.0.0",
"@angular/platform-browser-dynamic": "^5.0.0",
"@angular/router": "^5.0.0",
"core-js": "^2.4.1",
"rxjs": "^5.5.2",
"zone.js": "^0.8.14"
},
"devDependencies": {
"@angular/cli": "1.5.0",
"@angular/compiler-cli": "^5.0.0",
"@angular/language-service": "^5.0.0",
"@types/node": "~6.0.60",
"codelyzer": "~3.2.0",
"ts-node": "~3.2.0",
"tslint": "~5.7.0",
"typescript": "~2.4.2"
}