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

Class constructor XYZ cannot be invoked without 'new' #919

Closed
mschipperheyn opened this issue Feb 10, 2019 · 2 comments
Closed

Class constructor XYZ cannot be invoked without 'new' #919

mschipperheyn opened this issue Feb 10, 2019 · 2 comments

Comments

@mschipperheyn
Copy link
Contributor

mschipperheyn commented Feb 10, 2019

There is a problem that I have when extending classes from packages in node_modules e.g. sequelize and other tools such as apollo-rest-client. It is caused by trying to extend transpiled classes.

Discussions about this can be found here:
sequelize/sequelize#7840
apollographql/apollo-server#2216
and many other places.

There is a PR open for this issue @babel babel/babel#8656 bur who knows if and when it gets merged.

The common suggested workaround is applying

               [
			"@babel/preset-env",
			{
				"targets": {
					"node": "current"
				}
			}
		]

Unfortunately, that doesn't work with razzle, presumably because @babel/plugin-transform-runtime is used which is one of the other suggestions to solve this: remove that library.

Does anyone have this same problem and possibly a workaround? It's starting to hit me in more and more of the libraries I want to use.

@mschipperheyn
Copy link
Contributor Author

Workaround / Fixed:

babel.config.js

const razzleBabel = require('razzle/babel');

module.exports = function babelConfig(api) {
	api.cache(true);

	const babel = razzleBabel();

	babel.presets[0] =
		process.env.BUILD_TARGET === 'client'
			? [
				require.resolve('@babel/preset-env'),
				{
					modules: false,
				},
			  ]
			: [
				require.resolve('@babel/preset-env'),
				{
					targets: {
						node: 'current',
					},
					exclude: [
						'babel-plugin-transform-classes',
						'@babel/plugin-transform-classes',
					],
					modules: false,
				},
			  ];
              [...]

@1Jesper1
Copy link

1Jesper1 commented Nov 13, 2019

Hello @mschipperheyn Could you describe your fix? When I add

targets: {
 node: 'current',
},

to my babel.rc I get the following error:

ReferenceError: regeneratorRuntime is not defined

Babel 7 and Node 12

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

No branches or pull requests

2 participants