我正在使用CEAN应用程序。当我尝试为角运行npm start时出现以下错误:

时间:2017-07-14 14:24:43

标签: node.js angular mean-stack

我的应用程序运行正常,但在我为快速服务器安装了一些模块之后突然开始出现角度误差。安装完这些模块后如

"bcryptjs": "*",
"connect-flash": "*",
"cookie-parser": "^1.4.3",
"express-messages": "*",
"express-session": "*",
"express-validator": "*",
"passport": "*",
"passport-http": "*",
"passport-local": "*"

express server运行正常,但是当我没有添加或修改任何包时,为什么我在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:\installedSoftwares\nodejs\node_modules\npm\bin\node-gyp-bin;D:\installedSoftwares\wamp64\www\test\work\integration7\client\node_modules\.bin;C:\Users\admin\AppData\Roaming\npm;D:\installedSoftwares\nodejs\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;D:\installedSoftwares\nodejs\;C:\Program Files\Git\cmd;C:\Program Files (x86)\Skype\Phone\;C:\Python27;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files (x86)\Brackets\command;C:\Users\admin\AppData\Local\atom\bin;C:\Users\admin\AppData\Roaming\npm;C:\Program Files (x86)\Microsoft VS Code\bin;D:\installedSoftwares\curl;D:\installedSoftwares\Couchbase\Server\bin
    8 verbose lifecycle myappclient@1.0.0~prestart: CWD: D:\installedSoftwares\wamp64\www\test\work\integration7\client
    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:\installedSoftwares\nodejs\node_modules\npm\lib\utils\lifecycle.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:\installedSoftwares\nodejs\node_modules\npm\lib\utils\spawn.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:\installedSoftwares\wamp64\www\test\work\integration7\client
    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"
      }
    }

============================================= 

我已经尝试过以下内容:

  1. 使用'npm install'
  2. 删除'node_modules'文件夹并再次安装软件包
  3. 将“@ types / node”的修改版本改为最新版本
  4. 将“typescript”修改为“*”,“2.3.0”,“^ 2.3”
  5. 感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

经过一些调查后我才明白问题出现是因为我为Server安装了一些库。仔细安装模块后,我发现express-validator具有以下依赖关系:

`-- 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

因此,express-validator添加了bluebird,这导致了打字稿的问题。 在我进一步研究之后,我明白我需要使用typescript“2.3.2”。因此,我还修改并安装了typescript版本“2.3.2”for angular。

现在我的问题得到了解决,但我仍有疑问。

为什么客户端(Angular / Typescript)导致为Server(Express)安装的模块出现问题,因为它们都有自己的node_modules文件夹?它们是如何相关的?可能是一个微不足道的问题,但我缺乏这个概念。

提前感谢您的详细解答。

相关问题