evanw / node-source-map-support

Adds source map support to node.js (for stack traces)
MIT License
2.16k stars 223 forks source link

Cannot find module 'source-map' from 'source-map-support.js' #265

Open examineyou65 opened 4 years ago

examineyou65 commented 4 years ago

I am created react project by using npx create-react-app. I have installed jest package for unit test. when I was run unit test, this Cannot find module 'source-map' from 'source-map-support.js' error occur. I couldn't find any solution. Please do the needful.

I have tried reinstall source map support module but no use on that.

cmf-joo commented 4 years ago

Exact same problem. I created a minimal project to try to troubleshoot the problem, basically with sum.js and sum.test.js. When I run the test, it fails with the below message:

 FAIL  ./sum.test.js
  ● Test suite failed to run

    Cannot find module 'source-map' from 'source-map-support.js'

      at Resolver.resolveModule (H:/WORKSPACE/tmp/testProj/node_modules/jest-resolve/build/index.js:259:17)
      at Object.<anonymous> (node_modules/source-map-support/source-map-support.js:1:114)

My versions: npm@6.13.4 node@v12.14.0 Windows10

examineyou65 commented 4 years ago

@cmf-joo This problem was not related to source map support. did you run your project any Network or Ram Disk Path like virtual computer? If yes then change your jest config modulepath.

cmf-joo commented 4 years ago

My project is set up on a local folder on a local machine. Were you able to find a solution?

andinoJamesV commented 4 years ago

This appears to be 1/2 a NYC issue https://github.com/istanbuljs/nyc/issues/1323

Exploring further I can see that there is a logic error in nyc for the include flag

https://github.com/istanbuljs/nyc/blob/992359a1e2108906e28324058008f28aa1052dc1/index.js#L133

./node_modules/.bin/nyc --require source-map-support/register.js --source-map=false  ./node_modules/mocha/bin/mocha o/Test/Spork.js

will load the source maps library but line numbers are still incorrect. I guess that's what the cute @ symbols are all about

Probably because the source map library hooks require improperly in NYC?

Meanwhile looking at NYC and its instrument code the source map flags seem completely super broken ( there is no particular logic to toggling them on and off and making a Boolean chart of the results ) and I can not imagine where to look to figure out why simply including source mapping options on results in failing to cover anything as the instrument files look ~ the same just including or not including source map comments.

( Unless as I type this I am thinking requiring the library to handle source maps is breaking NYCs require hook )

I think the issue is non standard hooking of require but Im not sure