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

babel-generator crashes with SourceMapGenerator is not a constructor #9032

Open
hugmanrique opened this Issue Nov 16, 2018 · 4 comments

Comments

Projects
None yet
3 participants
@hugmanrique

hugmanrique commented Nov 16, 2018

Bug Report

Current Behavior
I'm running Babel using the webpack babel-loader (.babelrc file below).

Everytime I start webpack, @babel/generator crashes with the following error:

D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\@babel\generator\lib\source-map.js:30
      const map = this._cachedMap = new (_sourceMap().default.SourceMapGenerator)({
                                    ^

TypeError: _sourceMap(...).default.SourceMapGenerator is not a constructor
    at SourceMap.get (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\@babel\generator\lib\source-map.js:30:37)
    at Object.get (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\@babel\generator\lib\buffer.js:58:33)
    at generateCode (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\@babel\core\lib\transformation\file\generate.js:71:7)
    at runSync (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\@babel\core\lib\transformation\index.js:50:51)    at transformSync (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\@babel\core\lib\transform.js:43:38)
    at Object.transform (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\@babel\core\lib\transform.js:22:38)
    at compile (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\@babel\register\lib\node.js:73:20)
    at compileHook (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\@babel\register\lib\node.js:102:12)
    at Module._compile (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:77:29)
    at Module._extensions..js (module.js:660:10)
    at Object.newLoader [as .js] (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:88:7)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)
    at Function.Module._load (module.js:493:3)
    at Module.require (module.js:593:17)
    at require (internal/module.js:11:18)
    at Object.require (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\snapdragon\lib/utils.js:8:21)
    at Module._compile (module.js:649:30)
    at Module._compile (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:83:24)
    at Module._extensions..js (module.js:660:10)
    at Object.newLoader [as .js] (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:88:7)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)
    at Function.Module._load (module.js:493:3)
    at Module.require (module.js:593:17)
    at require (internal/module.js:11:18)
    at Object.require (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\snapdragon\lib/compiler.js:6:13)
    at Module._compile (module.js:649:30)
    at Module._compile (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:83:24)
    at Module._extensions..js (module.js:660:10)
    at Object.newLoader [as .js] (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:88:7)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)
    at Function.Module._load (module.js:493:3)
    at Module.require (module.js:593:17)
    at require (internal/module.js:11:18)
    at Object.require (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\snapdragon/index.js:5:16)
    at Module._compile (module.js:649:30)
    at Module._compile (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:83:24)
    at Module._extensions..js (module.js:660:10)
    at Object.newLoader [as .js] (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:88:7)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)
    at Function.Module._load (module.js:493:3)
    at Module.require (module.js:593:17)
    at require (internal/module.js:11:18)
    at Object.require (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\braces\lib/braces.js:4:18)
    at Module._compile (module.js:649:30)
    at Module._compile (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:83:24)
    at Module._extensions..js (module.js:660:10)
    at Object.newLoader [as .js] (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:88:7)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)
    at Function.Module._load (module.js:493:3)
    at Module.require (module.js:593:17)
    at require (internal/module.js:11:18)
    at Object.require (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\braces/index.js:17:14)
    at Module._compile (module.js:649:30)
    at Module._compile (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:83:24)
    at Module._extensions..js (module.js:660:10)
    at Object.newLoader [as .js] (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:88:7)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)
    at Function.Module._load (module.js:493:3)
    at Module.require (module.js:593:17)
    at require (internal/module.js:11:18)
    at Object.require (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\micromatch/index.js:8:14)
    at Module._compile (module.js:649:30)
    at Module._compile (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:83:24)
    at Module._extensions..js (module.js:660:10)
    at Object.newLoader [as .js] (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:88:7)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)
    at Function.Module._load (module.js:493:3)
    at Module.require (module.js:593:17)
    at require (internal/module.js:11:18)
    at Object.require (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\anymatch/index.js:3:18)
    at Module._compile (module.js:649:30)
    at Module._compile (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:83:24)
    at Module._extensions..js (module.js:660:10)
    at Object.newLoader [as .js] (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:88:7)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)
    at Function.Module._load (module.js:493:3)
    at Module.require (module.js:593:17)
    at require (internal/module.js:11:18)
    at Object.require (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\chokidar/index.js:6:16)
    at Module._compile (module.js:649:30)
    at Module._compile (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:83:24)
    at Module._extensions..js (module.js:660:10)
    at Object.newLoader [as .js] (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:88:7)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)
    at Function.Module._load (module.js:493:3)
    at Module.require (module.js:593:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (../../../src/static/getRoutes/getRoutesFromPages.js:2:1)
    at Module._compile (module.js:649:30)
    at Module._compile (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:83:24)
    at Module._extensions..js (module.js:660:10)
    at Object.newLoader [as .js] (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:88:7)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)
    at Function.Module._load (module.js:493:3)
    at Module.require (module.js:593:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (../../../src/static/getRoutes/index.js:4:1)
    at Module._compile (module.js:649:30)
    at Module._compile (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:83:24)
    at Module._extensions..js (module.js:660:10)
    at Object.newLoader [as .js] (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:88:7)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)
    at Function.Module._load (module.js:493:3)
    at Module.require (module.js:593:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (../../src/static/prepareRoutes.js:5:1)
    at Module._compile (module.js:649:30)
    at Module._compile (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:83:24)
    at Module._extensions..js (module.js:660:10)
    at Object.newLoader [as .js] (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:88:7)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)
    at Function.Module._load (module.js:493:3)
    at Module.require (module.js:593:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (../../src/static/preparePlugins.js:6:1)
    at Module._compile (module.js:649:30)
    at Module._compile (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:83:24)
    at Module._extensions..js (module.js:660:10)
    at Object.newLoader [as .js] (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:88:7)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)
    at Function.Module._load (module.js:493:3)
    at Module.require (module.js:593:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (../../src/static/index.js:4:1)
    at Module._compile (module.js:649:30)
    at Module._compile (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:83:24)
    at Module._extensions..js (module.js:660:10)
    at Object.newLoader [as .js] (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:88:7)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)
    at Function.Module._load (module.js:493:3)
    at Module.require (module.js:593:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (../../src/commands/start.js:3:1)
    at Module._compile (module.js:649:30)
    at Module._compile (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:83:24)
    at Module._extensions..js (module.js:660:10)
    at Object.newLoader [as .js] (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\node_modules\pirates\lib\index.js:88:7)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)
    at Function.Module._load (module.js:493:3)
    at Module.require (module.js:593:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (D:\Users\[REDACTED]\AppData\Roaming\npm\node_modules\react-static\bin\react-static-start:5:18)
    at Module._compile (module.js:649:30)
    at Object.Module._extensions..js (module.js:660:10)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)
    at Function.Module._load (module.js:493:3)
    at Function.Module.runMain (module.js:690:10)
    at startup (bootstrap_node.js:194:16)
    at bootstrap_node.js:666:3

My code gets compiled correctly on another webpack setup that uses the following babel packages:

{
    "@babel/core": "^7.0.0-beta.56",
    "@babel/plugin-proposal-class-properties": "^7.0.0-beta.56",
    "@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.56",
    "@babel/plugin-syntax-dynamic-import": "^7.0.0-rc.1",
    "@babel/plugin-transform-modules-commonjs": "^7.0.0-rc.1",
    "@babel/preset-env": "^7.0.0-beta.56",
    "@babel/preset-react": "^7.0.0-beta.56"
}

And the following .babelrc file:

{
  "presets": [
    "@babel/preset-env",
    "@babel/preset-react"
  ],
  "plugins": [
    "@babel/plugin-syntax-dynamic-import",
    "@babel/plugin-proposal-object-rest-spread",
    "@babel/plugin-proposal-class-properties"
  ],
  "env": {
    "production": {
      "plugins": [
        "babel-plugin-transform-react-remove-prop-types"
      ]
    }
  }
}

Expected behavior/code

Babel shouldn't crash or provide a clearer message if this is a mistake I made in my code 😛.

Babel Configuration (.babelrc, package.json, cli command)

https://github.com/nozzle/react-static/blob/v6/packages/react-static/babel-preset.js

Environment

  • Babel version: 7.1.6
  • @babel/generator version: 7.1.6
  • Node/npm version: 9.8.0
  • OS: Windows 10
  • Monorepo: no
  • How you are using Babel: loader
@babel-bot

This comment has been minimized.

Collaborator

babel-bot commented Nov 16, 2018

Hey @hugmanrique! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

@loganfsmyth

This comment has been minimized.

Member

loganfsmyth commented Nov 17, 2018

Can you show the code where you're loading @babel/register?

This does seem like a @babel/register bug, but I'm not sure how I'd resolve it honestly.

For now the quick fix would be including source-map in your ignore option for @babel/register

@loganfsmyth

This comment has been minimized.

Member

loganfsmyth commented Nov 17, 2018

Essentially, because you're likely overriding the default ignore value, @babel/register is actually being told to compile a file that it actually needs in order to compile files, creating a dependency cycle. Unfortunately detecting and handling that might be pretty hard.

@hugmanrique

This comment has been minimized.

hugmanrique commented Nov 17, 2018

I'm using react-static, so I'm not loading @babel/register directly, but I will create an issue on their repo.

Haven't tested the ignore fix, but will do once I have more time. Thanks for the help 😀

bkniffler added a commit to bkniffler/react-static that referenced this issue Dec 14, 2018

@bkniffler bkniffler referenced this issue Dec 14, 2018

Merged

Fix issues with windows paths #872

1 of 1 task complete

tannerlinsley added a commit to nozzle/react-static that referenced this issue Dec 14, 2018

Fix issues with windows paths (#872)
* Fix issue due to @babel/register ignore

See babel/babel#9032

* use escapeRegExp, windows path separator

* Fix windows path resolution

* Small fix

* Fix lint

* Add lodash

It is already installed by multiple dependencies, so no added weight ;)

* Remove lodash

* Remove lodash usage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment