angular / angular-cli

CLI tool for Angular
https://cli.angular.io
MIT License
26.68k stars 11.98k forks source link

Error: Cannot find module 'package.json' #1898

Closed ThomasKnobloch closed 7 years ago

ThomasKnobloch commented 7 years ago
  1. OS? Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?) Mac OS X 10.11.5 (El Capitan)
  2. Versions. Please run ng --version. If there's nothing outputted, please run in a Terminal: node --version and paste the result here: angular-cli: 1.0.0-beta.11-webpack.8 node: 6.5.0 os: darwin x64
  3. Repro steps. Was this an app that wasn't created using the CLI? What change did you do on your code? etc. clone from repository npm install --save-dev angular-cli@webpack ng version
  4. The log given by the failure. Normally this include a stack trace and some more information.
Cannot find module 'package.json'
Error: Cannot find module 'package.json'
    at Function.Module._resolveFilename (module.js:455:15)
    at Function.Module._load (module.js:403:25)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at AddonDiscovery.discoverAtPath (/Users/thomasknobloch/workspace/OXEWbm2/wbm/node_modules/angular-cli/lib/models/addon-discovery.js:205:20)
    at AddonDiscovery.<anonymous> (/Users/thomasknobloch/workspace/OXEWbm2/wbm/node_modules/angular-cli/lib/models/addon-discovery.js:114:26)
    at Array.map (native)
    at AddonDiscovery.discoverFromDependencies (/Users/thomasknobloch/workspace/OXEWbm2/wbm/node_modules/angular-cli/lib/models/addon-discovery.js:109:68)
    at AddonDiscovery.discoverProjectAddons (/Users/thomasknobloch/workspace/OXEWbm2/wbm/node_modules/angular-cli/lib/models/addon-discovery.js:48:29)
    at Project.discoverAddons (/Users/thomasknobloch/workspace/OXEWbm2/wbm/node_modules/angular-cli/lib/models/project.js:353:40)
  1. Mention any other details that might be useful. ng version works fine outside of my project (using the global installation of angular-cli).
ThomasKnobloch commented 7 years ago

The problem seems to be in the module ember-cli, the package child_process in the devDependencies of my package.json cannot be resolved. There is no more issue when I delete this module in the package.json file of my project.

filipesilva commented 7 years ago

We had the problem a while ago, but it's fixed in the latest versions.

CoreyCole commented 7 years ago

It's happening to me currently on: angular-cli: 1.0.0-beta.16 node: v6.8.1 npm: 3.10.8

I've tried wiping node modules and reinstalling the cli after a fresh install of node and npm. Still no luck

filipesilva commented 7 years ago

@CoreyCole what happened to you was probably fixed by https://github.com/angular/angular-cli/pull/2178, available in beta.17.

EpicButterz commented 7 years ago

I'm having this same problem on beta 18.

Cannot find module 'package.json'
Error: Cannot find module 'package.json'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at AddonDiscovery.discoverAtPath (/Users/ewbutterfield/vs/pct-service/node_modules/angular-cli/lib/models/addon-discovery.js:205:20)
    at AddonDiscovery.<anonymous> (/Users/ewbutterfield/vs/pct-service/node_modules/angular-cli/lib/models/addon-discovery.js:114:26)
    at Array.map (native)
    at AddonDiscovery.discoverFromDependencies (/Users/ewbutterfield/vs/pct-service/node_modules/angular-cli/lib/models/addon-discovery.js:109:68)
    at AddonDiscovery.discoverProjectAddons (/Users/ewbutterfield/vs/pct-service/node_modules/angular-cli/lib/models/addon-discovery.js:48:29)
    at Project.discoverAddons (/Users/ewbutterfield/vs/pct-service/node_modules/angular-cli/lib/models/project.js:353:40)
    at Project.initializeAddons (/Users/ewbutterfield/vs/pct-service/node_modules/angular-cli/lib/models/project.js:372:8)
    at Project.eachAddonCommand (/Users/ewbutterfield/vs/pct-service/node_modules/angular-cli/lib/models/project.js:425:10)
    at module.exports (/Users/ewbutterfield/vs/pct-service/node_modules/angular-cli/lib/cli/lookup-command.js:33:13)
    at CLI.<anonymous> (/Users/ewbutterfield/vs/pct-service/node_modules/angular-cli/lib/cli/cli.js:34:26)
    at tryCatch (/Users/ewbutterfield/vs/pct-service/node_modules/rsvp/dist/rsvp.js:538:12)
    at invokeCallback (/Users/ewbutterfield/vs/pct-service/node_modules/rsvp/dist/rsvp.js:553:13)
    at publish (/Users/ewbutterfield/vs/pct-service/node_modules/rsvp/dist/rsvp.js:521:7)
    at flush (/Users/ewbutterfield/vs/pct-service/node_modules/rsvp/dist/rsvp.js:2373:5)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)

angular-cli: 1.0.0-beta.18 node: v6.9.1 npm: 3.10.8

filipesilva commented 7 years ago

This doesn't seem to happen to everyone, and I can't repro. Will leave it open for community help.

AmitMY commented 7 years ago

Try 'Npm install --save http' It will add "http" on version 0.0.0 This reliably reproduces the problem Tried 3 times, and that is the error.

I can send a video if you want.

filipesilva commented 7 years ago

@AmitMY got it, thank you!

kamik@T460p MINGW64 /D/sandbox/master-proj (master)
$ ng version
angular-cli: local (v1.0.0-beta.19, branch: fix-broken-e2e-tests)
node: 6.5.0
os: win32 x64

kamik@T460p MINGW64 /D/sandbox/master-proj (master)
$ npm install http --save
master-proj@0.0.0 D:\sandbox\master-proj
+-- UNMET PEER DEPENDENCY @types/request@0.0.30
`-- http@0.0.0

npm WARN optional Skipping failed optional dependency /angular-cli/chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.0.15
npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.0.15
npm WARN angularfire2@2.0.0-beta.5 requires a peer of @types/request@0.0.30 but none was installed.

kamik@T460p MINGW64 /D/sandbox/master-proj (master)
$ ng version
Cannot find module 'package.json'
Error: Cannot find module 'package.json'
    at Function.Module._resolveFilename (module.js:455:15)
    at Function.Module._load (module.js:403:25)
    at Function.Module._load (D:\work\angular-cli\lib\bootstrap-local.js:64:22)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at AddonDiscovery.discoverAtPath (D:\work\angular-cli\node_modules\angular-cli\lib\models\addon-discovery.js:205:20)
    at AddonDiscovery.<anonymous> (D:\work\angular-cli\node_modules\angular-cli\lib\models\addon-discovery.js:114:26)
    at Array.map (native)
    at AddonDiscovery.discoverFromDependencies (D:\work\angular-cli\node_modules\angular-cli\lib\models\addon-discovery.js:109:68)
    at AddonDiscovery.discoverProjectAddons (D:\work\angular-cli\node_modules\angular-cli\lib\models\addon-discovery.js:48:29)
    at Project.discoverAddons (D:\work\angular-cli\node_modules\angular-cli\lib\models\project.js:353:40)
    at Project.initializeAddons (D:\work\angular-cli\node_modules\angular-cli\lib\models\project.js:372:8)
    at Project.eachAddonCommand (D:\work\angular-cli\node_modules\angular-cli\lib\models\project.js:425:10)
    at module.exports (D:\work\angular-cli\node_modules\angular-cli\lib\cli\lookup-command.js:33:13)
    at CLI.<anonymous> (D:\work\angular-cli\node_modules\angular-cli\lib\cli\cli.js:34:26)
    at tryCatch (D:\work\angular-cli\node_modules\rsvp\dist\rsvp.js:538:12)
    at invokeCallback (D:\work\angular-cli\node_modules\rsvp\dist\rsvp.js:553:13)
    at publish (D:\work\angular-cli\node_modules\rsvp\dist\rsvp.js:521:7)
    at flush (D:\work\angular-cli\node_modules\rsvp\dist\rsvp.js:2373:5)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)
filipesilva commented 7 years ago

As far as I can tell, it's something that is broken with ember-cli's addon discovery in the specific version we use.

chris-gaona commented 7 years ago

Just an FYI for anyone else dealing with this issue. I received a similar error message when I would run any angular cli commands (ng serve, ng version etc.) saying Error: Cannot find module 'package.json. I found out that the issue was caused by using a bad npm package (crypto), although I'm not entirely sure why that would have caused the error. When I removed that package from my package.json file, all the angular cli commands worked perfectly. I'm now using bcrypt instead.

gglee89 commented 7 years ago

Was this issue solved? :(

I'm getting the same issue on:

$ node --version
v5.1.0
$ npm -v
4.0.2
$ npm show angular-cli version
1.0.0-beta.20-4

This is my console output:

$ ng version
Cannot find module 'package.json'
Error: Cannot find module 'package.json'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:289:25)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at AddonDiscovery.discoverAtPath (/Users/giwoogustavolee/Documents/proof-gis-map/node_modules/angular-cli/lib/models/addon-discovery.js:205:20)
    at AddonDiscovery.<anonymous> (/Users/giwoogustavolee/Documents/proof-gis-map/node_modules/angular-cli/lib/models/addon-discovery.js:114:26)
    at Array.map (native)
    at AddonDiscovery.discoverFromDependencies (/Users/giwoogustavolee/Documents/proof-gis-map/node_modules/angular-cli/lib/models/addon-discovery.js:109:68)
    at AddonDiscovery.discoverProjectAddons (/Users/giwoogustavolee/Documents/proof-gis-map/node_modules/angular-cli/lib/models/addon-discovery.js:48:29)
    at Project.discoverAddons (/Users/giwoogustavolee/Documents/proof-gis-map/node_modules/angular-cli/lib/models/project.js:353:40)
    at Project.initializeAddons (/Users/giwoogustavolee/Documents/proof-gis-map/node_modules/angular-cli/lib/models/project.js:372:8)
    at Project.eachAddonCommand (/Users/giwoogustavolee/Documents/proof-gis-map/node_modules/angular-cli/lib/models/project.js:425:10)
    at module.exports (/Users/giwoogustavolee/Documents/proof-gis-map/node_modules/angular-cli/lib/cli/lookup-command.js:33:13)
    at CLI.<anonymous> (/Users/giwoogustavolee/Documents/proof-gis-map/node_modules/angular-cli/lib/cli/cli.js:34:26)
    at tryCatch (/Users/giwoogustavolee/Documents/proof-gis-map/node_modules/rsvp/dist/rsvp.js:538:12)
    at invokeCallback (/Users/giwoogustavolee/Documents/proof-gis-map/node_modules/rsvp/dist/rsvp.js:553:13)
    at publish (/Users/giwoogustavolee/Documents/proof-gis-map/node_modules/rsvp/dist/rsvp.js:521:7)
    at flush (/Users/giwoogustavolee/Documents/proof-gis-map/node_modules/rsvp/dist/rsvp.js:2373:5)
    at doNTCallback0 (node.js:430:9)
    at process._tickCallback (node.js:359:13)
MarkySparky commented 7 years ago

I had the same issue. I removed the http package from my dev dependencies and it all started to work.

beeman commented 7 years ago

This happened to me when I made a copy of a project and ran ng serve in the copy. My solution was to nuke node_modules and run npm install.

I can not reproduce this with a new version of the app though.

WeslleyDeSouza commented 7 years ago

i had the same problem with FS from nodejs so i had to remove fs package from my dev dependencies and it all started to work again. "fs": "0.0.1-security",

Caspain commented 7 years ago

After much reading and analysis, the crypto package cause ember-cli to panic. Just remove it npm uninstall crypto --save

Caspain commented 7 years ago

There seems to be a correlation with streaming associated packages

rikkouri commented 7 years ago

Hi @filipesilva ,

I'm quite new to this world of nodejs/angular etc. but hopefully this helps diagnose a fix...

I found that running strace highlighted a lot of stat syscalls failing towards the end of its execution. It seems that ng is looking for a directory called node_modules/package.json/ which certainly didn't exist in my project. However I did notice that package-json does exist.

Adding a symlink between the two seem to fix the issue for me. Could this be a simple typo in a recent release?

Does this help?

ln -s node_modules/package-json/ node_modules/package.json

strace output for reference:

$ strace ng serve

...
open("/home/rikkouri/WebstormProjects/issue-1898/node_modules/package.json/package.json", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/rikkouri/WebstormProjects/issue-1898/node_modules/package.json/index.js", 0x7fffc0f829b0) = -1 ENOENT (No such file or directory)
stat("/home/rikkouri/WebstormProjects/issue-1898/node_modules/package.json/index.json", 0x7fffc0f829b0) = -1 ENOENT (No such file or directory)
stat("/home/rikkouri/WebstormProjects/issue-1898/node_modules/package.json/index.node", 0x7fffc0f829b0) = -1 ENOENT (No such file or directory)
...
write(9, "\33[31mCannot find module 'package"..., 44Cannot find module 'package.json'
) = 44
write(9, "Error: Cannot find module 'packa"..., 2041Error: Cannot find module 'package.json'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at AddonDiscovery.discoverAtPath (/home/rikkouri/WebstormProjects/issue-1898/node_modules/angular-cli/ember-cli/lib/models/addon-discovery.js:205:20)
    at AddonDiscovery.<anonymous> (/home/rikkouri/WebstormProjects/issue-1898/node_modules/angular-cli/ember-cli/lib/models/addon-discovery.js:114:26)
    at Array.map (native)
    at AddonDiscovery.discoverFromDependencies (/home/rikkouri/WebstormProjects/issue-1898/node_modules/angular-cli/ember-cli/lib/models/addon-discovery.js:109:68)
    at AddonDiscovery.discoverProjectAddons (/home/rikkouri/WebstormProjects/issue-1898/node_modules/angular-cli/ember-cli/lib/models/addon-discovery.js:48:29)
    at Project.discoverAddons (/home/rikkouri/WebstormProjects/issue-1898/node_modules/angular-cli/ember-cli/lib/models/project.js:296:40)
    at Project.initializeAddons (/home/rikkouri/WebstormProjects/issue-1898/node_modules/angular-cli/ember-cli/lib/models/project.js:315:8)
    at Project.eachAddonCommand (/home/rikkouri/WebstormProjects/issue-1898/node_modules/angular-cli/ember-cli/lib/models/project.js:368:10)
    at module.exports (/home/rikkouri/WebstormProjects/issue-1898/node_modules/angular-cli/ember-cli/lib/cli/lookup-command.js:33:13)
    at CLI.<anonymous> (/home/rikkouri/WebstormProjects/issue-1898/node_modules/angular-cli/ember-cli/lib/cli/cli.js:43:26)
    at tryCatch (/home/rikkouri/WebstormProjects/issue-1898/node_modules/rsvp/dist/rsvp.js:538:12)
    at invokeCallback (/home/rikkouri/WebstormProjects/issue-1898/node_modules/rsvp/dist/rsvp.js:553:13)
    at publish (/home/rikkouri/WebstormProjects/issue-1898/node_modules/rsvp/dist/rsvp.js:521:7)
    at flush (/home/rikkouri/WebstormProjects/issue-1898/node_modules/rsvp/dist/rsvp.js:2373:5)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)
) = 2041
...
filipesilva commented 7 years ago

Fixed by https://github.com/angular/angular-cli/pull/3695

RanaAbdullah2017 commented 6 years ago

[ERROR] Error with .\node_modules\ionic-angular\package.json file: FILE_NOT_FOUND [ERROR] Error with .\node_modules\@ionic\app-scripts\package.json file: FILE_NOT_FOUND I have an above Error when I write this command ionic start Myapp tabs Can u help me to solve this problem.

beeman commented 6 years ago

@RanaAbdullah2017 this is the Angular CLI issue thread, please look for the Ionic support channels when you have problems running Ionic.

gabrielfrischer commented 6 years ago

I like turtles

saidevops014 commented 6 years ago

at Module._compile (module.js:635:30) at Object.Module._extensions..js (module.js:646:10) at Module.load (module.js:554:32) at tryModuleLoad (module.js:497:12) Error: Cannot find module '/usr/local/share/.pm2/package.json' at Function.Module._resolveFilename (module.js:536:15) at Function.Module._load (module.js:466:25) at Module.require (module.js:579:17) at require (internal/module.js:11:18) at getPublicUrl (/usr/local/share/applications/cms-admin-ui/config/paths.js:26:19) at Object. (/usr/local/share/applications/cms-admin-ui/config/paths.js:54:14) at Module._compile (module.js:635:30) at Object.Module._extensions..js (module.js:646:10) at Module.load (module.js:554:32) at tryModuleLoad (module.js:497:12)

when i start the application through PM2 am facing this issue please give me the solution for this ..

angular-automatic-lock-bot[bot] commented 4 years ago

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.