node-source-map-support: Module not found: Error: Cannot resolve module 'module' in [...]source-map-support @ source-map-support.js 464:17-34

I am using source-map-support 0.4.5 in a module of mine (let’s call it moduleA).

I then publish moduleA to npm and all’s well till that point.

Then I try to use that moduleA in another project of mine (let’s call it moduleUser). After I do npm install in moduleUser I try to do an npm run build which is configured in package.json as:

$ grep \"build\"\: package.json 
    "build": "webpack --progress --colors",

… and I then encounter (at the end of the build process) the following message which I can’t decipher:

ERROR in …/~/moduleA/~/source-map-support/source-map-support.js Module not found: Error: Cannot resolve module ‘module’ in /home/carsten/moduleUser/node_modules/moduleA/node_modules/source-map-support @ …/~/moduleA/~/source-map-support/source-map-support.js 464:17-34

Looking in the identified location in file source-map-support.js the line is:

var Module = require('module');

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 21
  • Comments: 29

Commits related to this issue

Most upvoted comments

Seeing the same issue in 0.5.1, as well as unresolved ‘fs’ module. The following addition to the top level of my webpack.config.js fixes it:

node: {
    fs: "empty",
    module: "empty"
 }

I still see this issue in 0.4.11.

Nailing the source-map-support version to 0.4.3 indeed fixes the problem.

I am using Angular 5, Angular cli 1.5.2 and everything was fine until I added and used import * as ts from "typescript";

My error starts with

WARNING in ./node_modules/source-map-support/source-map-support.js
Module not found: Error: Can't resolve 'module' in '/usr/local/app/node_modules/source-map-support'
resolve 'module' in '/usr/local/app/node_modules/source-map-support'
  Parsed request is a module
  using description file: /usr/local/app/node_modules/source-map-support/package.json (relative path: .)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: /usr/local/app/node_modules/source-map-support/package.json (relative path: .)
    resolve as module
      /usr/local/app/node_modules/source-map-support/node_modules doesn't exist or is not a directory
      /usr/local/app/node_modules/node_modules doesn't exist or is not a directory
      /usr/local/node_modules doesn't exist or is not a directory
      /usr/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory
      looking for modules in /usr/local/app/node_modules
        using description file: /usr/local/app/package.json (relative path: ./node_modules)
          Field 'browser' doesn't contain a valid alias configuration
        after using description file: /usr/local/app/package.json (relative path: ./node_modules)
          using description file: /usr/local/app/package.json (relative path: ./node_modules/module)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /usr/local/app/node_modules/module doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              /usr/local/app/node_modules/module.ts doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /usr/local/app/node_modules/module.js doesn't exist
            as directory
              /usr/local/app/node_modules/module doesn't exist

And continues something like 1000 more lines… Not sure what I can do about it. Any idea? Here is my package.json.

{
  "name": "app",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --host=0.0.0.0 --port=80 --disable-host-check --poll=500",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^5.1.0",
    "@angular/cdk": "^5.0.0",
    "@angular/common": "^5.0.0",
    "@angular/compiler": "^5.0.0",
    "@angular/core": "^5.0.0",
    "@angular/forms": "^5.0.0",
    "@angular/http": "^5.0.0",
    "@angular/material": "^5.0.0",
    "@angular/platform-browser": "^5.0.0",
    "@angular/platform-browser-dynamic": "^5.0.0",
    "@angular/router": "^5.0.0",
    "angular-new-router": "github:angular/router",
    "angular2-draggable": "^1.0.7",
    "core-js": "^2.4.1",
    "hammerjs": "^2.0.8",
    "immutable": "^3.8.2",
    "jquery": "^3.2.1",
    "jquery-ui": "^1.12.1",
    "monaco-editor": "^0.10.1",
    "ng-drag-drop": "^4.0.0",
    "rxjs": "^5.5.2",
    "zone.js": "^0.8.14"
  },
  "devDependencies": {
    "@angular/cli": "1.5.2",
    "@angular/compiler-cli": "^5.0.0",
    "@angular/language-service": "^5.0.0",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/jquery": "^3.2.16",
    "@types/jqueryui": "^1.11.37",
    "@types/node": "~6.0.60",
    "codelyzer": "~3.2.0",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "~2.4.2"
  }
}

I have this issue with v0.4.18. Downgraded to v0.4.3 and issue still exists. But I have

+-- babel-core@6.26.0
| `-- babel-register@6.26.0
|   `-- source-map-support@0.4.18

And I think babel-core uses 0.4.18 no matter of source-map-support installed package on top level. I didn’t have this issue long time, because in my React/Webpack codebase I didn’t have require('module') untill now. And I rather need it for some time, which later on, myabe, will be removed/moved/modified/deprecated.

But the issue interesting. AMD vs. CJS.

Then I changed my webpack.config.js and added one more line:

node: {
	fs: 'empty',
	module: 'empty'
}

And issue gone. Partially.

Such behavior is odd 😃 Just imagine, 2018 year, we work on NPM modules, module is essential for require/CJS and we have to add some explicit code to “see” it 😃

But it’s not the end. My webpack build process is OK, and warning is suppressed, but when I run my application, when the code tries to access to require(‘module’) I have error in console:

Uncaught TypeError: module.config is not a function

And here is my piece of code:

test.js

define(function(require) {
    'use strict';

    var _ = require('underscore'),
        module = require('module'),
        Backbone = require('backbone'),
        Marionette = require('marionette');

    console.log(module); // OK

    var configFallback = {
        icons: 'svg'
    };
    var moduleConfig = _.extend(configFallback, module.config()); 
    // => ERROR

});

In fact my console.log(module); is an empty {} object. and I know it should be object with properties (exports, config, etc).

I manage code to provide config, but I though there is always by default some module.config() => {} at least. Not sure.

ANyway, I changed my code to this:

var moduleConfig = _.isFunction(module.config) ? _.extend(configFallback, module.config()) : {};

And now webpack/react based app at least works with no errors. But still, it’s no ideal fix I assume.

I have a similar issue:

next These dependencies were not found:
next 
next * fs in ./node_modules/source-map-support/source-map-support.js
next * module in ./node_modules/source-map-support/source-map-support.js
next 
next To install them, you can run: npm install --save fs module

For anyone having the issue with the Next.js library, here is the workaround:

next.config.js

module.exports = {
  webpack: (config, { buildId, dev, isServer, defaultLoaders }) => {
    config.node = {
      fs: 'empty',
      module: "empty",
    };
    return config;
  },
};

https://github.com/webpack-contrib/css-loader/issues/447#issuecomment-368345121

Still seeing in 0.5.0 😢 removing ‘^’ from package.json does not solve the issue

I don’t know what am doing wrong please someone help take a look at my config and how i tried to apply the workaround.

`var Encore = require(‘symfony/webpack-encore’);

Encore

.setOutputPath('public/build/')

.setPublicPath('/build')
.cleanupOutputBeforeBuild()
.enableSourceMaps(!Encore.isProduction())


.addEntry('public', './assets/js/public.js')
.addEntry('member', './assets/js/member.js')
.addEntry('admin', './assets/js/admin.js')

.addStyleEntry('global', './assets/css/global.scss')

.createSharedEntry('vendor', [
    'jquery'


])


 .enableSassLoader(function(sassOptions) {}, {
         resolveUrlLoader: false
 })

/trying to add the work around here and i get error/

.node({ fs:‘empty’ })

.enableBuildNotifications()

 .autoProvidejQuery()

;

module.exports = Encore.getWebpackConfig();`

when i run yarn run encore dev i get error ` Error: Encore.node is not a recognized property or method.

  • index.js:942 Object.get [chukolo]/[@symfony]/webpack-encore/index.js:942:27

  • webpack.config.js:44 Object.<anonymous> C:/xampp/htdocs/chukolo/webpack.config.js:44:5

  • module.js:652 Module._compile module.js:652:30

  • module.js:663 Object.Module._extensions…js module.js:663:10

  • module.js:565 Module.load module.js:565:32

  • module.js:505 tryModuleLoad module.js:505:12

  • module.js:497 Function.Module._load module.js:497:3

  • module.js:596 Module.require module.js:596:17

  • module.js:11 require internal/module.js:11:18

  • convert-argv.js:97 requireConfig [chukolo]/[webpack]/bin/convert-argv.js:97:18

error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this comm and. `

I still see this issue in 0.5.4.

attention