Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mperdikeas opened this issue Oct 21, 2016 · 29 comments · Fixed by #273

Comments

@mperdikeas
Copy link

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');
@mmmeff
Copy link

mmmeff commented Oct 24, 2016

Also started receiving this same error on our production builds.

@jknight12882
Copy link

Receiving this as well

@mmmeff
Copy link

mmmeff commented Oct 25, 2016

You can circumvent it by adding source-map-support@0.4.3 to your
project.json. It'll force the resolution for babel-register and avoid the
latent issues in 0.4.4+

On Oct 24, 2016 12:40 PM, "Jeff Knight" notifications@github.com wrote:

Receiving this as well


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#155 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AA8w8E1PBDEB2tArvmfIr6ntsiypFuXQks5q3QmsgaJpZM4KdeZ7
.

@mperdikeas
Copy link
Author

Having ^0.4.3 in my package.json:

$ cat package.json | grep \"source-map-support\"
    "source-map-support": "^0.4.3"

… actually fetches 0.4.5:

$ npm ls --depth=0 | grep source-map-support
└── source-map-support@0.4.5

… and the same problem persists after npm-publishing the package and using it from another project.

@mmmeff
Copy link

mmmeff commented Oct 25, 2016

@mperdikeas So remove the ^ from ^0.4.3 ...

https://docs.npmjs.com/misc/semver#caret-ranges-123-025-004

@mperdikeas
Copy link
Author

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

@TamsynUlthara
Copy link

I've been seeing the same issue, and likewise ended up pinning to 0.4.3. I'm also using Webpack for my builds, for what that's worth.

@jknight12882
Copy link

Any chance this is going to get fixed? Stuck on 0.4.3 until this is resolved

@levino
Copy link

levino commented Jan 10, 2017

Same issue here.

@LinusU
Copy link
Collaborator

LinusU commented Jan 10, 2017

Hmm, I thought that we fixed this, is still a problem in 0.4.8?

edit: maybe not after all...

it's probably just a matter of wrapping require('module') in a try/catch, anyone up for trying it out and sending a pr? 💌

@veeramarni
Copy link

I still see this issue in 0.4.11.

jmfirth added a commit to jmfirth/typescript-playground that referenced this issue Mar 30, 2017
@w3irdrobot
Copy link

Still seeing it in 0.4.17

@pmunin
Copy link

pmunin commented Oct 17, 2017

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

@Ventzy
Copy link

Ventzy commented Dec 22, 2017

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"
  }
}

@noahgibbs
Copy link

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"
 }

@Vadorequest
Copy link

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;
  },
};

webpack-contrib/css-loader#447 (comment)

@sunny920406
Copy link

attention

@sunny920406
Copy link

I still see this issue in 0.5.4.

@alundiak
Copy link

alundiak commented Mar 28, 2018

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.

@akoh-victor
Copy link

akoh-victor commented May 18, 2018

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.
    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.
`

@akvsh-r
Copy link

akvsh-r commented Jan 16, 2019

Is there any solution for this problem yet? facing the same thing.

@amithole0206
Copy link

I am getting error when running angular 5 application using npm command.

ERROR in ./node_modules/source-map-support/source-map-support.js
Module not found: Error: Can't resolve 'path' in 'C:\TCSrc\Trunk\Dev\Client\node_modules\source-map-support'

@akoh-victor
Copy link

Is there any solution for this problem yet? facing the same thing.

What worked for me was deleting my instance of yarn and webencore then reinstalling it. sorry for the late reply

@akoh-victor
Copy link

can you confirm that this (source-map-support' )was installed to your node_modules dir ?
iff you are using npm https://docs.npmjs.com/cli/install
or
yarn add package name.
confirm the package name by checking https://yarnpkg.com/en/

@nogo10
Copy link

nogo10 commented Apr 23, 2020

I get same error Module not found: Error: Can't resolve 'module' in ..node_modules/source-map-support in versions 0.5.16, 0.5.18, and 0.4.18 (versions used in my packages)

@LinusU
Copy link
Collaborator

LinusU commented Apr 23, 2020

@mperdikeas, @nogo10, and anyone else in this thread; could you try #273 and see if that fixes the problem for you?

@nogo10
Copy link

nogo10 commented Apr 23, 2020

To test it I copy pasted source-map-support.js code fix at #273 to replace instances in my app packages that use source-map-support.

Seems to work: I no longer get the Module not found ... error
(I do still get an unrelated scrypt error
.../node_modules/web3-eth-accounts/src/scrypt.js Critical dependency: the request of a dependency is an expression )

@LinusU
Copy link
Collaborator

LinusU commented Apr 24, 2020

Fixed in version 0.5.19 🚀

@iPatrickReynolds
Copy link

To fix this I noticed that sourcemap was installed under myproject/node_modules/css_loader/node_modules/source-map/source-map.js

I grabbed the file, renamed it sourceMaps.js and saved it here: myproject/node_modules/css_loader/dist/runtime/sourceMaps.js

That fixed it. My guess is that the sourceMaps file has the same logic in most cases, but is setup in a different directory now than in the past. I'm guessing that the structure changed for how the node_modules subfolders get setup within css-loader. Probably older versions still assume that the necessary file lives at /dist/runtime/sourceMaps.js

Probably there's a way to remap where the project is looking for sourceMaps.js and what it is called, but I find that copy and pasting a file is much simpler and seems appropriately mundane.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.