babel: preset-react v7 build error

Mentioning this error I have, since I haven’t found it in issues, while trying to update babel to use jsx fragments

I’m using a valid webpack config, running webpack fails with:

ERROR in ./app/index.js
Module build failed: TypeError: Cannot read property 'throwIfNamespace' of undefined (While processing preset: "/home/caub/dev/projX/node_modules/@babel/preset-react/lib/index.js")
    at _default (/home/caub/dev/projX/node_modules/@babel/plugin-transform-react-jsx/lib/index.js:15:36)

.babelrc

{
	"presets": [
		"@babel/preset-react",
		[
			"@babel/preset-env",
			{
				"targets": {
					"browsers": ["last 2 versions", "not ie > 0", "not Android > 0"]
				}
			}
		]
	]
}

package.json

"@babel/core": "^7.0.0-beta.32",
"@babel/preset-env": "^7.0.0-beta.32",
"@babel/preset-react": "^7.0.0-beta.32",
"@babel/preset-stage-3": "^7.0.0-beta.32",
software version(s)
Babel @7.0.0-beta.32
node 9.2
npm 5.5.1
Operating System Linux

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 5
  • Comments: 20 (7 by maintainers)

Commits related to this issue

Most upvoted comments

Working with these pacakges:

    "@babel/core": "^7.0.0-beta.38",
    "@babel/preset-env": "^7.0.0-beta.36",
    "@babel/preset-react": "^7.0.0-beta.36",
    "babel-core": "^7.0.0-bridge.0",
    "babel-jest": "^22.1.0",
    "babel-loader": "^8.0.0-beta.0",

Thanks yes with babel-loader ^8.0.0-beta.0 it builds fine The only remaining points is to update eslint and editors (vscode, sublime) for fragments, even markdown parsers fail

(
  <>
    <span>test</span>
    <div>
      foo
    </div>
  </>
)

also jest is throwing that Cannot read property 'throwIfNamespace' of undefined error

symlinking babel-core to @babel/core can work or npm i -D babel-core@7.0.0-bridge.0 (< might be helpful for @stephen-last)

Yes using babel-core@7.0.0-bridge.0 is required for babel-jest with Babel 7 because we renamed the package to @babel/core and Jest expects babel-core. The bridge package just passes through to @babel/core.

see my comment just above with babel-core@7.0.0-bridge.0

at Pipeline.transform (/home/caub/dev/projX/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
at transpile (/home/caub/dev/projX/node_modules/babel-loader/lib/index.js:50:20)

babel-loader is using babel-core not @babel/core, you’ll have to use babel-loader@8.0.0-beta.0 because it’s a breaking change for us otherwise to switch from @babel/core and babel-core. although we could try the bridge package still

I’m using babel-loader@8.0.0-beta.0 already…

Currently searching for other deps that may use babel-core