We are working on the following module js(javascript only), which allows to generate random colors. Link: Github
When we try to install the module on an example on codesandbox, we have no problem.
But when we install the module on a local project, we get the following error:
./node_modules/random-colors-palette/randomColors.js 141:39
Module parse failed: Unexpected token (141:39)
File was processed with these loaders:
* ./node_modules/react-scripts/node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| if (!repeat) {
| delete cc[hueNumber].shades[shadeR[0]];
> if (Object.entries(cc[hueNumber]?.shades).length === 0) cc.splice(hueNumber, 1);
| }
|
The problem seems to be due to the use of the ?
(The optional concatenation operator) in the line in question.
How can we solve the problem, do I need to add some other files in the project configuration to make sure I don't have these problems?
The module should not only be used for reactjs, but also as a module pure js code.
Can you give us a hand?
You need
babel-plugin-proposal-optional-chaining
.It is included in
ES2020
babel preset.Your
.babelrc
should beIf you don't use a preset add the plugin manually to your babel config