我的应用程序运行良好,但在我为快速服务器安装了一些模块后突然开始出现这些 angular 错误。安装这些模块后,例如
"bcryptjs": "*",
"connect-flash": "*",
"cookie-parser": "^1.4.3",
"express-messages": "*",
"express-session": "*",
"express-validator": "*",
"passport": "*",
"passport-http": "*",
"passport-local": "*"
快速服务器运行良好,但是为什么当我没有添加或修改任何包时,我在 Angular 中收到这些错误。我不认为它们是相关的,那么为什么突然我开始出现这些错误:
> tsc -p src/
../node_modules/@types/bluebird/index.d.ts(50,17): error TS1005: ',' expected.
../node_modules/@types/bluebird/index.d.ts(50,31): error TS1005: ',' expected.
../node_modules/@types/bluebird/index.d.ts(1079,59): error TS1005: ']' expected.
../node_modules/@types/bluebird/index.d.ts(1079,60): error TS1005: ';' expected.
../node_modules/@types/bluebird/index.d.ts(1079,61): error TS1128: Declaration or statement expected
.
../node_modules/@types/bluebird/index.d.ts(1079,81): error TS1109: Expression expected.
../node_modules/@types/bluebird/index.d.ts(1164,1): error TS1128: Declaration or statement expected.
npm ERR! Windows_NT 6.1.7601
=============================
Command: npm -v, Results : 4.2.0
Command: node -v, Results : v7.8.0
Command: tsc -v, Results : Version 2.3.4
=============================
Following files are attached for reference:
1. Following are from npm Debug File Info generated when tried 'npm start':
0 info it worked if it ends with ok
1 verbose cli [ 'D:\installedSoftwares\nodejs\node.exe',
1 verbose cli 'D:\installedSoftwares\nodejs\node_modules\npm\bin\npm-cli.js',
1 verbose cli 'start' ]
2 info using npm@4.2.0
3 info using node@v7.8.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle myappclient@1.0.0~prestart: myappclient@1.0.0
6 verbose lifecycle myappclient@1.0.0~prestart: unsafe-perm in lifecycle true
7 verbose lifecycle myappclient@1.0.0~prestart: PATH: D:installedSoftwaresnodejsnode_modulesnpmbinnode-gyp-bin;D:installedSoftwareswamp64wwwtestworkintegration7clientnode_modules.bin;C:UsersadminAppDataRoamingnpm;D:installedSoftwaresnodejs;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;D:installedSoftwaresnodejs;C:Program FilesGitcmd;C:Program Files (x86)SkypePhone;C:Python27;C:Program Files (x86)Windows Kits8.1Windows Performance Toolkit;C:Program Files (x86)Bracketscommand;C:UsersadminAppDataLocalatombin;C:UsersadminAppDataRoamingnpm;C:Program Files (x86)Microsoft VS Codebin;D:installedSoftwarescurl;D:installedSoftwaresCouchbaseServerbin
8 verbose lifecycle myappclient@1.0.0~prestart: CWD: D:installedSoftwareswamp64wwwtestworkintegration7client
9 silly lifecycle myappclient@1.0.0~prestart: Args: [ '/d /s /c', 'npm run build' ]
10 silly lifecycle myappclient@1.0.0~prestart: Returned: code: 2 signal: null
11 info lifecycle myappclient@1.0.0~prestart: Failed to exec prestart script
12 verbose stack Error: myappclient@1.0.0 prestart: `npm run build`
12 verbose stack Exit status 2
12 verbose stack at EventEmitter.<anonymous> (D:installedSoftwaresnodejsnode_modulesnpmlibutilslifecycle.js:279:16)
12 verbose stack at emitTwo (events.js:106:13)
12 verbose stack at EventEmitter.emit (events.js:194:7)
12 verbose stack at ChildProcess.<anonymous> (D:installedSoftwaresnodejsnode_modulesnpmlibutilsspawn.js:40:14)
12 verbose stack at emitTwo (events.js:106:13)
12 verbose stack at ChildProcess.emit (events.js:194:7)
12 verbose stack at maybeClose (internal/child_process.js:899:16)
12 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
13 verbose pkgid myappclient@1.0.0
14 verbose cwd D:installedSoftwareswamp64wwwtestworkintegration7client
15 error Windows_NT 6.1.7601
16 error argv "D:\installedSoftwares\nodejs\node.exe" "D:\installedSoftwares\nodejs\node_modules\npm\bin\npm-cli.js" "start"
17 error node v7.8.0
18 error npm v4.2.0
19 error code ELIFECYCLE
20 error errno 2
21 error myappclient@1.0.0 prestart: `npm run build`
21 error Exit status 2
22 error Failed at the myappclient@1.0.0 prestart script 'npm run build'.
22 error Make sure you have the latest version of node.js and npm installed.
22 error If you do, this is most likely a problem with the myappclient package,
22 error not with npm itself.
22 error Tell the author that this fails on your system:
22 error npm run build
22 error You can get information on how to open an issue for this project with:
22 error npm bugs myappclient
22 error Or if that isn't available, you can get their info via:
22 error npm owner ls myappclient
22 error There is likely additional logging output above.
23 verbose exit [ 2, true ]
2. Following snippet is for package.json_forAngular
{
"name": "myappclient",
"version": "1.0.0",
"description": "QuickStart package.json from the documentation, supplemented with testing support",
"scripts": {
"build": "tsc -p src/",
"build:watch": "tsc -p src/ -w",
"build:e2e": "tsc -p e2e/",
"serve": "lite-server -c=bs-config.json",
"serve:e2e": "lite-server -c=bs-config.e2e.json",
"prestart": "npm run build",
"start": "concurrently "npm run build:watch" "npm run serve"",
"pree2e": "npm run build:e2e",
"e2e": "concurrently "npm run serve:e2e" "npm run protractor" --kill-others --success first",
"preprotractor": "webdriver-manager update",
"protractor": "protractor protractor.config.js",
"pretest": "npm run build",
"test": "concurrently "npm run build:watch" "karma start karma.conf.js"",
"pretest:once": "npm run build",
"test:once": "karma start karma.conf.js --single-run",
"lint": "tslint ./src/**/*.ts -t verbose"
},
"keywords": [],
"author": "",
"license": "MIT",
"dependencies": {
"@angular/common": "~2.4.0",
"@angular/compiler": "~2.4.0",
"@angular/core": "~2.4.0",
"@angular/forms": "~2.4.0",
"@angular/http": "~2.4.0",
"@angular/platform-browser": "~2.4.0",
"@angular/platform-browser-dynamic": "~2.4.0",
"@angular/router": "~3.4.0",
"@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.25",
"angular-in-memory-web-api": "~0.2.4",
"angular2-google-chart": "^2.3.0",
"core-js": "^2.4.1",
"postcss-loader": "^2.0.1",
"raw-loader": "^0.5.1",
"rxjs": "5.0.1",
"sass-loader": "^6.0.3",
"systemjs": "0.19.40",
"zone.js": "^0.7.4"
},
"devDependencies": {
"concurrently": "^3.2.0",
"lite-server": "^2.2.2",
"typescript": "*",
"canonical-path": "0.0.2",
"tslint": "^3.15.1",
"lodash": "^4.16.4",
"jasmine-core": "~2.4.1",
"karma": "^1.3.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~4.0.14",
"rimraf": "^2.5.4",
"@types/node": "*",
"@types/jasmine": "2.5.36"
},
"repository": {}
}
3. Following are from package.json forExpress
{
"name": "myapp",
"version": "1.0.0",
"description": "A Couchbase, Express, Angular 2, & NodeJS (CEAN) app",
"main": "server.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"devstart": "nodemon server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "*",
"body-parser": "^1.16.1",
"connect-flash": "*",
"cookie-parser": "^1.4.3",
"couchbase": "^2.3.3",
"debug": "^2.6.6",
"ejs": "^2.5.5",
"express": "^4.14.1",
"express-messages": "*",
"express-session": "*",
"express-validator": "*",
"mongojs": "^2.4.0",
"morgan": "^1.8.1",
"nodemon": "^1.11.0",
"passport": "*",
"passport-http": "*",
"passport-local": "*",
"request": "^2.81.0",
"serve-favicon": "^2.4.2"
},
"devDependencies": {
"nodemon": "^1.11.0"
}
}
=============================================
我已经尝试了以下方法:
- 删除了"node_modules"文件夹并使用"npm install"再次安装软件包
- 将"@types/节点"修改为最新版本
- 将"打字稿"修改为"*"、"2.3.0"、"^2.3">
感谢您的帮助。
经过一些调查,我明白出现问题是因为我已经为服务器安装了一些库。在仔细安装模块后,我开始知道表达式验证器具有以下依赖项:
`-- express-validator@3.2.1
+-- @types/bluebird@3.5.8
+-- @types/express@4.0.36
| +-- @types/express-serve-static-core@4.0.49
| | `-- @types/node@8.0.13
| `-- @types/serve-static@1.7.31
| `-- @types/mime@1.3.1
+-- bluebird@3.5.0
+-- lodash@4.17.4
`-- validator@6.2.1
因此,快递验证器添加了蓝鸟,这导致了打字稿的问题。 经过进一步的研究,我明白我需要使用打字稿"2.3.2"。因此,我还修改并安装了 angular 的打字稿版本"2.3.2"。
现在我的问题解决了,但我仍然有一个问题。
为什么客户端(Angular/Typescript(导致为Server(Express(安装的模块出现问题,因为它们都有自己的node_modules文件夹?它们有什么关系?也许这是一个微不足道的问题,但我缺乏这个概念。
提前感谢您的详细回答。