为什么npm试图在错误的目录中找到package.json?

时间:2016-04-07 12:56:56

标签: angularjs json node.js npm package-managers

我正在使用TypeScript,Angular和多个依赖项的Web应用程序。

当然,npm当然也在这里。 从package.json的乞讨开始,npm init引入了该项目,现在它看起来像是:

{
  "name": "myApp",
  "version": "0.0.8-d",
  "description": "Web App",
  "author": "Author",
  "license": "ISC",
  "repository": {
    "type": "git",
    "url": "MYURL"
  },
  "bugs": {
    "url": "MYURL"
  },
  "homepage": "MYURL",
  "browserify": {
    "transform": [
      "debowerify"
    ]
  },
  "dependencies": {
    "malihu-custom-scrollbar-plugin": "^3.1.3"
  },
  "devDependencies": {
    "browserify": "~13.0.0",
    "connect-history-api-fallback": "^1.2.0",
    "connect-modrewrite": "^0.8.2",
    "debowerify": "~1.2.0",
    "gulp": "^3.9.1",
    "gulp-autoprefixer": "^3.1.0",
    "gulp-clean-css": "^2.0.4",
    "gulp-concat": "^2.6.0",
    "gulp-connect": "^3.2.2",
    "gulp-less": "^3.0.5",
    "gulp-ng-annotate": "^2.0.0",
    "gulp-sass": "^2.2.0",
    "gulp-sourcemaps": "^1.6.0",
    "gulp-typescript": "^2.12.2",
    "gulp-uglify": "^1.5.3",
    "jasmine": "^2.4.1",
    "run-sequence": "^1.1.5",
    "typescript": "^1.8.9",
    "vinyl-source-stream": "^1.1.0"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  }
}

我的文件结构也是这样的:

Root
|-- tscode
|-- compiled
|-- html_files
|-- node_modules
|-- libs
| package.json

这个想法是npm似乎工作正常,一切都安装正确我可以添加/删除依赖项但是我总是这样工作:

npm WARN enoent ENOENT: no such file or directory, open '/Projects/MyApp/tscode/package.json'

package.json是应该在根文件夹上,但我仍然收到这个非常烦人的警告。正如你可以看到npm在一个文件夹中搜索json文件,而不是在根目录中搜索。

如果我这样做: npm list --depth=0

然后我得到了一个正确的依赖列表但是: - > /Projects/MyApp/innerfolder extraneous error: ENOENT: no such file or directory, open '/Projects/MyApp/tscode/package.json

有什么想法吗?

节点版本:v5.10.1 npm版本:3.8.5

注意:无论操作系统如何,我的团队中都会发生这种情况。

更新:似乎npm存在错误。 npm存储库中存在一些未解决的问题,例如:

如果有变化,我会用答案(如果提供)更新问题

1 个答案:

答案 0 :(得分:0)

试试这个:

Delete node_modules folder

然后运行:

$ npm cache clean
$ npm install