bim2016
bim2016

Reputation: 105

Error: Cannot find module 'concat-map' when i try to run command line npm like "npm init"

when i try to publish package to npm, i got the following error, happens when i run npm commands like "npm init", "npm publish", etc., how to fix it?

$ npm init node:internal/modules/cjs/loader:933 const err = new Error(message); ^

Error: Cannot find module 'concat-map' Require stack:

Upvotes: 0

Views: 2341

Answers (1)

Viradex
Viradex

Reputation: 3768

There are a few things that you can do to remove this error message.


Firstly, you can simply try and install everything again by simply running the command below in a directory where a package.json file is present.

$ npm install

Secondly, make sure that the package supports either require() or import.

Normally, it would have it on the homepage of the npm website.

If you find out that the module uses require(), use the following steps.

  1. Remove the following from package.json.

    {
      "type": "module"
    }
    
  2. Replace the import statement with the below in your JavaScript code.

    const concatMap = require("concat-map");
    

If you realise it needs the import statement, follow these steps.

  1. Add the following in package.json.

    {
      "type": "module"
    }
    
  2. Replace the require() function with the import statement in your JavaScript code.

    import concatMap from "concat-map";
    

Thirdly, if you are publishing to npm, make sure that the package is listed in the dependencies section of package.json.

{
  "dependencies": {
    "concat-map": "^0.0.1"
  }
}

Note: This version was the current version of the package at the time of writing.


Fourthly, you can reinstall Node.js and npm.

  1. Install and run the LTS installer from nodejs.org. It will overwrite the already-present version.

This should fix the issue if the problem based on a bug fixed in later versions.


These are some steps you can take to make sure that concat-map is working correctly, and to rid the error.

Upvotes: 0

Related Questions