Issue: Module '@angular/compiler-cli/src/perform_compile' not found while executing ng-packagr

I recently installed Windows and am attempting to use ng-packagr for the first time.

Encountering the following error:

Error: Cannot locate 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 have already installed Angular CLI by running

npm install -g @angular/cli@latest

Current version is v6.0.8

This is my ng-package.json:

{
    "$schema": "./node_modules/ng-packagr/ng-package.schema.json",
    "lib": {
        "entryFile": "index.ts",
        "externals": {
            "moment": "moment"
        }
    }
}

What could I be overlooking?

Answer №1

If you've encountered a similar issue, here's a solution you might want to try:

  1. Start by updating node.js to the latest version (Make sure to uninstall the previous one)

  2. Next, globally install the latest angular-cli version

    npm uninstall -g angular-cli
    npm cache clean or npm cache verify (if npm > 5)
    npm install -g @angular/cli@latest
    
  3. Create a new project using angular-cli ng new projectname

  4. Transfer your files (modules, components, directives, etc.) from the old project to the newly created one

  5. Install ng-packagr npm i ng-packagr

  6. Update the package.json file in the root of your project

    "scripts": {
        "packagr": "ng-packagr -p ng-package.json"
    }
    

    Consider removing dependencies or moving them to peerDependencies if you are creating a feature module

  7. Adjust the ng-package.json file according to your needs

    {
      "$schema": "./node_modules/ng-packagr/ng-package.schema.json",
      "lib": {
        "entryFile": "public_api.ts"
      }
    }
    
  8. Update the public_api.ts file with the correct relative path to your module

    export * from './src/app/modules/yourmodulename/yourmodulename.module
    

After completing these steps, run npm run packagr to generate the dist folder.

You can then publish on npmjs using npm publish dist

This method worked for me and hopefully, it helps you resolve the issue as well.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for resolving the out of sync error when deploying a React app to gcloud

Despite attempting to install using npm and npm cli, I am still encountering the same error message as displayed in the terminal window. = Uploading 1 file to Google Cloud Storage =# #================================================ ...

Encountering an issue: Module './src/init' not found while attempting to set up a React Native app

After attempting to set up react native using the command react-native init ProjectName The result is: When trying to create a new React Native project in C:\Users\Xegano\Documents\ProjectName Installing react-native package from npm. ...

Determining the most appropriate time to utilize the 'async' built-in function in ES2017 versus implementing 'npm i async' can depend on a variety of factors such

I recently discovered that async/await is a feature of ES2017, however, in some of my previous projects I had to use the package async to implement async/await functionality. Is there a simple way to determine when async can be used without importing it? ...

Babel error: "Issue: Module 'babel-plugin-transform-object-rest-spread' not located within '/vagrant'"

While attempting to upgrade from Babel 6 to Babel 7, I utilized npx babel-upgrade --write for updating the package.json and proceeded with a npm install. However, upon trying to run our webpack dev server, compilation failed with this error: ERROR in ./s ...

Upgrade the package to the latest major version using NPM

When working on a Node.js project, the process of upgrading a package to a major release may seem unclear at first glance. For example, let's say I want to install stylelint: npm install --save stylelint By default, this command adds "stylelin ...

Having trouble accessing the GitHub Package Registry account

As I attempt to publish an npm package through GitHub Package Registry, I am closely following the provided documentation. However, whenever I try to log in using the command below after entering my correct username and password, I consistently encounter t ...

Every time I try to install npm, I am bombarded with a massive error log

I recently downloaded the Vue Black Dashboard from this GitHub repository (https://github.com/creativetimofficial/vue-black-dashboard), but when I tried running npm install, I encountered a lengthy error log that left me confused. For context, I am operat ...

Discovering the origins of the node.js native modules and delving into the intricacies of typed modules

I am using a Windows machine and trying to locate where node fetches the source code for native modules. On my system, I can only find the @types file which contains "Typed Only" modules. For example, the module "assert" is available in the master/lib fold ...

The proper approach for managing downloaded d.ts files from DefinitelyTyped after installation through npm

Visual Studio 2017 Enterprise ASP.NET MVC Application TypeScript 2.5 SDK Source control is in TFS I have opted to use Microsoft's built-in property editor instead of creating a custom tsconfig.config file: To streamline my workflow, I rely on Mad&ap ...

Error encountered during yarn installation: Module build has failed due to inability to locate preset "es2015"

Currently, I am in need of utilizing react-select: https://github.com/JedWatson/react-select. To implement this, it was necessary for me to initially install yarn on Ubuntu 14.04. However, subsequent to the installation and running of yarn add react-select ...

Encountered an error stating 'WeakCallbackData' template does not exist in the 'v8' namespace while trying to install npm packages

There are some issues with installing certain packages that rely on https://www.npmjs.com/package/fibers, such as iron-meteor. The homepage of fibers advises meteor users to take a specific action, but it may not be very helpful. One suggestion provided ...

Angular authentication guard does not redirect properly after returning a Promise<UrlTree>

My authentication guard is set up to control access to the /sign-in and /verify-email routes, allowing only users who are not logged in or have not verified their email: export const signInGuard: CanActivateFn = (activatedRouteSnapshot: ActivatedRouteSnap ...

Is there a way to log into yarn without needing to interact with it manually?

One way to login non-interactively using npm is: $ printf "jesstelford\n<password>\<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7b151e031a160b171e3b1e161a121755181416">[email protected]</a>&bsol ...

Having trouble installing sqlite3 dependency using npm

Running Pop!_OS (Ubuntu) 20.04 poses a challenge when attempting to add sqlite3 as a dependency in a nodejs project, resulting in an onslaught of warnings: npm WARN deprecated <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cbb9 ...

Execute Laravel Mix without the need for a system-wide installation of Node.js and npm

Currently working on a Laravel project that requires building styles and scripts using laravel-mix. However, the testing server (Ubuntu 20.04.4) does not have Node globally installed. Node and npm are located in separate folders within the system, so I hav ...

When executing `npm run dev` and `npm run start`, a TypeError [ERR_INVALID_ARG_TYPE] is generated along with an [Error: ENOENT: no

I encountered this issue while running npm run dev: PS C:\Users\19043\node_projects\nortech_retail> npm run dev > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a4cacbd6d0c1c7ccfbd6c1d0c5cdc8e4948a958 ...

Encountering the error message 'No such module' while using npm with node.js on Mac OS X

I have tried both installing node.js v0.8.8 from the pkg installer and compiling it from source. However, I keep encountering an error when attempting to run npm. Any assistance would be greatly appreciated. > $ npm --help > > /usr/lib/node_m ...

Encountering a module not found error while accessing Node.js via SSH in Virtualbox

I have set up a Debian stretch minimal installation in Virtualbox, running headless, to test a node application. To install a dependency for my node application, I used sudo npm install -g discord.js. I opted for a global installation because the director ...

Unable to download packages for a React application

Every time I run npm install, I receive this message indicating that everything is up to date. I attempted to modify my npm versions and also ran npm update. I removed the resolutions and preinstall from the package.json file. Additionally, I deleted the ...

I am receiving no response from the NPM commands whatsoever

I recently updated Node.js to the latest version and ran the command 'node -v' in PowerShell, which returned 'v18.14.0'. However, when I tried the 'npm -v' command, there was no output or recognition of the command in PowerShe ...