【问题标题】:Moving node_modules directory causes syntax errors移动 node_modules 目录会导致语法错误
【发布时间】:2018-04-13 04:24:55
【问题描述】:

我有一个令我困惑的语法错误。 我在运行的同一目录中有一个 node_modules 目录 npm run tsc 一切正常,没有语法错误。

出于避免你的原因,我将 node_modules 目录移动到我的主目录 ~ 。没有目录更改,我重新运行 npm run tsc 并得到语法错误:

../../../../../node_modules/@types/react-select/index.d.ts(18,46): error TS1005: ',' expected.

../../../../../node_modules/@types/react-select/index.d.ts(22,31): 错误 TS1005: ',' 预期。 ../../../../../node_modules/@types/react-select/index.d.ts(23,27): 错误 TS1005: ',' 预期。 ../../../../../node_modules/@types/react-select/index.d.ts(24,36): 错误 TS1005: ',' 预期。 ../../../../../node_modules/@types/react-select/index.d.ts(29,39): 错误 TS1005: ',' 预期。 ../../../../../node_modules/@types/react-select/index.d.ts(30,39): error TS1005: ',' 预期。

package.json 是:

    {
  "name": "plugin",
  "version": "7.0.1",
  "scripts": {
    "tsc": "tsc -p tsconfig.json",
    "tsc:w": "tsc -p tsconfig.json -w",
    "lite": "lite-server",
    "start": "npm run tsc && concurrently \"npm run tsc:w\" \"npm run lite\" "
  },
  "license": "MIT",
  "dependencies": {
    "@angular/common": "4.2.6",
    "@angular/compiler": "4.2.6",
    "@angular/compiler-cli": "4.2.6",
    "@angular/core": "4.2.6",
    "@angular/forms": "4.2.6",
    "@angular/http": "4.2.6",
    "@angular/platform-browser": "4.2.6",
    "@angular/platform-browser-dynamic": "4.2.6",
    "@angular/platform-server": "4.2.6",
    "@angular/animations": "4.2.6",
    "@angular/router": "4.2.6",
    "ag-grid": "13.3.1",
    "ag-grid-angular": "13.3.0",
    "bootstrap": "3.3.6",
    "core-js": "2.4.1",
    "jquery": "3.1.1",
    "lodash": "4.17.4",
    "moment": "2.17.1",
    "rxjs": "5.4.2",
    "systemjs": "0.20.14",
    "zone.js": "0.8.12",
    "primeng": "^4.2.0",
    "ng2-split-pane": "^1.3.1",
    "font-awesome": "^4.7.0",
    "base64-js": "1.2.1",
    "@types/react": "^16.0.2",
    "@types/react-select": "^1.0.58",
    "lite-server": "2.2.2",
    "typescript": "^2.4.2",
    "concurrently": "3.5.0"
   }
}

有什么想法吗?

【问题讨论】:

    标签: node.js typescript npm


    【解决方案1】:

    您的node_modules 目录必须与package.json 位于同一目录中。如果您移动一个而不是另一个,或者不在带有package.json 的目录中运行npm install,则节点无法找到它要查找的内容。

    无论如何,您不应该首先手动移动您的 node_modules 文件夹。

    【讨论】:

    • 我所做的与将 package.json 复制到我的主目录并运行 npm install 没有什么不同。任何一种方法都会导致相同的错误
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-02
    • 2015-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-18
    相关资源
    最近更新 更多