Jsonforms Editor, optional chaining is not transpiled

Hi, trying to integrate react-grid-layout library with JsonForms editor. I got this error. Module parse failed: Unexpected token (203:74)

File was processed with these loaders:

  • …/node_modules/babel-loader/lib/index.js

You may need an additional loader to handle the result of these loaders.
I have @babel/plugin-proposal-optional chaining installed and made this change in the rollup config:
import babel from ‘rollup-plugin-babel’;
plugins: [typescript(), css(),babel({
presets: [
@babel/preset-env’
],
plugins: [‘@babel/plugin-proposal-optional-chaining’,‘@babel/plugin-transform-optional-chaining’]
}), json(), visualizer({ open: false })],
Still optional chasing is not transpiled. Any advice? Thanks.

Hi @mariap,

Are you talking about the JSON Forms editor?

The question is not really related to the JSON Forms libraries itself but is a typical bundling problem. Not sure how to help you there.

Yes, about JSON Forms editor, the one in the link. Practically, tried everything. Added @babel/plugin-proposal-nullish-coalescing-operator too. I’m modifying rollup.config? What I’m doing wrong?

Could you explain what do you mean? What kind of bundling problem? Problem is that babel loader doesn’t use these plugins when transpiling dependency libraries. So the question is what do I need to do to fix it. Also how big of an effort do you think is to update the visual editor to use webpack 5 and babel 8? Thanks!
I see all needed plugins on @babel directory. But they are not used.
My package.json looks like this

{
“name”: “root”,
“scripts”: {
“lerna”: “lerna”,
“init”: “lerna bootstrap --hoist”,
“build”: “lerna run build”,
“test”: “lerna run test”,
“lint”: “lerna run lint”,
“start”: “cd app && npm run start”,
“watch”: “cd jsonforms-editor && npm run watch”,
“cypress:open”: “cd app && npm run cypress:open”,
“cypress:ci”: “cd app && npm run cypress:ci”,
“preinstall”: “npx npm-force-resolutions”
},
“resolutions”: {
“acorn”: “8.0.1”
},
“devDependencies”: {
“jest-environment-jsdom-fourteen”: “^1.0.1”,
“lerna”: “^4.0.0”
},
“dependencies”: {
@babel/plugin-proposal-optional-chaining”: “^7.21.0”,
@babel/plugin-transform-optional-chaining”: “^7.23.4”,
@types/react-grid-layout”: “^1.3.4”,
“npm-force-resolutions”: “^0.0.10”,
“polished”: “^4.0.1”,
“react-grid-layout”: “^1.3.4”
}
}

The rollup configuration of the jsonforms-editor does not bundle any dependencies, so this error should not be introduced by react-grid-layout. Did you add react-grid-layout as a proper dependency to the package.json of the editor?

In general you should try to not introduce any dependencies in the root package.json.

There is nothing preventing you from using the latest webpack and babel. As you can see from our rollup configuration, we don’t do anything special in the jsonforms-editor, so the effort solely depends on the familiarity of the developer with tools like webpack.

Thanks for the answer. I moved the library to package.json of the editor. The same error.

I was able to integrate the library finally. It was a dependency problem. Thanks for pointing it out!
Now I have another problem. Looks like JsonForms removes property “key” from the “div” in the renderer. Practically ‘<div key="123"></div>' becomes '<div></div>’. But layout needs “key” identifier. Do you know why it’s being removed? Thanks!

Hi @mariap,

This is a React feature, key has very specific semantics. I don’t even know how to add a key attribute to the DOM without bypassing React.