manfredsteyer / ngx-build-plus

Extend the Angular CLI's default build behavior without ejecting, e. g. for Angular Elements
1.19k stars 136 forks source link

Cannot find module ngx-build-plus/package.json #301

Open AlissonRS opened 3 years ago

AlissonRS commented 3 years ago

Trying to use it in an Angular 12 app, but I get the error below when running ng serve:

An unhandled exception occurred: Cannot find module 'ngx-build-plus/package.json' Require stack: C:\Users\siri\repos\my-app\node_modules\@angular-devkit\architect\node\node-modules-architect-host.js C:\Users\siri\repos\my-app\node_modules\@angular-devkit\architect\node\index.js C:\Users\siri\repos\my-app\node_modules\@angular\cli\models\architect-command.js C:\Users\siri\repos\my-app\node_modules\@angular\cli\commands\serve-impl.js C:\Users\siri\repos\my-app\node_modules\@angular\cli\node_modules\@angular-devkit\schematics\tools\export-ref.js C:\Users\siri\repos\my-app\node_modules\@angular\cli\node_modules\@angular-devkit\schematics\tools\index.js C:\Users\siri\repos\my-app\node_modules\@angular\cli\utilities\json-schema.js C:\Users\siri\repos\my-app\node_modules\@angular\cli\models\command-runner.js C:\Users\siri\repos\my-app\node_modules\@angular\cli\lib\cli\index.js C:\Users\siri\repos\my-app\node_modules\@angular\cli\lib\init.js C:\Users\siri\repos\my-app\node_modules\@angular\cli\bin\ng at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15) at Function.resolve (internal/modules/cjs/helpers.js:98:19) at WorkspaceNodeModulesArchitectHost.resolveBuilder (C:\Users\siri\repos\my-app\node_modules\@angular-devkit\architect\node\node-modules-architect-host.js:113:41) at ServeCommand.initialize (C:\Users\siri\repos\my-app\node_modules\@angular\cli\models\architect-command.js:80:63) at async ServeCommand.validateAndRun (C:\Users\siri\repos\my-app\node_modules\@angular\cli\models\command.js:121:22) at async Object.runCommand (C:\Users\siri\repos\my-app\node_modules\@angular\cli\models\command-runner.js:224:24) at async default_1 (C:\Users\siri\repos\my-app\node_modules\@angular\cli\lib\cli\index.js:70:31)

What could be possibly wrong? Seems like an issue with path/folder structure that is making the customer builder not to find the package.json file (though it exists).

netikras commented 2 years ago

I'm getting this same exception in my GitLab CI, running ng build

This error goes away and build succeeds if I switch to shared runners. This error occurs if I run the job on my own runner (the server is located in Germany, IDK if relevant)

$ ng build
Node.js version v17.2.0 detected.
Odd numbered Node.js versions will not enter LTS status and should not be used for production. For more information, please see https://nodejs.org/en/about/releases/.
An unhandled exception occurred: Cannot find module 'ngx-build-plus/package.json'
Require stack:
- /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/architect/node/node-modules-architect-host.js
- /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/architect/node/index.js
- /usr/local/lib/node_modules/@angular/cli/models/architect-command.js
- /usr/local/lib/node_modules/@angular/cli/commands/build-impl.js
- /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/tools/export-ref.js
- /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/tools/index.js
- /usr/local/lib/node_modules/@angular/cli/utilities/json-schema.js
- /usr/local/lib/node_modules/@angular/cli/models/command-runner.js
- /usr/local/lib/node_modules/@angular/cli/lib/cli/index.js
- /usr/local/lib/node_modules/@angular/cli/lib/init.js
See "/tmp/ng-alCDEM/angular-errors.log" for further details.

ng build passes on that DE server if I run everything manually (docker run -it my-image sh, git clone, npm install, ng build)

netikras commented 2 years ago

Turns out I just needed an additional npm install before the ng build. Perhaps I've made some typo in my .gitlab-ci.yml that ended up in artifacts not being transferred between jobs...

ashwynair commented 2 years ago

Having the same issue. Anybody figure out how to sort this out? Is it possible to use this library with yarn and without nx?

netikras commented 2 years ago

Have you tried redownloading dependencies? A clean npm install worked for me.

aryajayan commented 2 years ago

Have you tried redownloading dependencies? A clean npm install worked for me. The same worked for me too. Thank you!

Xstream007 commented 1 year ago

I did npm i --legacy-peer-deps and then ng build but still getting the error. What can be the issue?