Error: Cannot find module '@angular/compiler-cli/src/perform_compile' when running ng-packagr
Hey recently solved a similar problem you can try following:
Install latest node.js (Uninstall the previous version)
Install the latest angular-cli globally
npm uninstall -g angular-cli npm cache clean or npm cache verify (if npm > 5) npm install -g @angular/cli@latest
Create a new project with angular-cli
ng new projectname
Copy your files (modules, component, directive etc.) into newly created project from your old one
Install ng-packagr
npm i ng-packagr
Edit your
package.json
(root project)"scripts": { "packagr": "ng-packagr -p ng-package.json" }
Remove dependencies or move all to peerDependencies since you are going to create a feature module
ng-package.json
(may be different in your case but you can try this){ "$schema": "./node_modules/ng-packagr/ng-package.schema.json", "lib": { "entryFile": "public_api.ts" } }
public_api.ts
(update relative path to your module)export * from './src/app/modules/yourmodulename/yourmodulename.module
And that's it now you can run npm run packagr
it should work and generate dist folder.
You can publish on npmjs using npm publish dist
That's how I resolved it.
Scottie
Updated on June 05, 2022Comments
-
Scottie over 1 year
I have a new install of windows and I'm trying to run ng-packagr for the first time.
I'm getting the error:
Error: Cannot find module '@angular/compiler-cli/src/perform_compile' at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Module.require (module.js:596:17) at require (internal/module.js:11:18) at Object.<anonymous> (C:\Users\MyUser\AppData\Roaming\npm\node_modules\ng-packagr\lib\ts\tsconfig.js:3:12) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3)
I did install the angular CLI by running
npm install -g @angular/cli@latest
It's running v6.0.8
My ng-package.json:
{ "$schema": "./node_modules/ng-packagr/ng-package.schema.json", "lib": { "entryFile": "index.ts", "externals": { "moment": "moment" } } }
What am I missing here?
-
Scottie over 5 yearsYeah,.I figured out you have to install ng-packagr v1.x or it won't work.