nbudin / react-blockly

A React component that embeds a Blockly visual programming editor.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

New blockly versions fail with ```No matching export in "node_modules/blockly/index.mjs" for import "default"```

diegonc opened this issue · comments

It seems that blockly package has no longer a default import causing Vite to display the following error:

 [ERROR] No matching export in "node_modules/blockly/index.mjs" for import "default"

    node_modules/react-blockly/dist/useBlocklyWorkspace.js:13:7:
      13 │ import Blockly from "blockly";
         ╵        ~~~~~~~

The blockly package README file now shows the import below:

import * as Blockly from 'blockly/core';

I tried to workaround the issue by installing an old blockly version (^10.0.0) in my package.json but react-blockly insists in using its own (latest, I guess) version. Maybe a peer dependency needs to be used instead.

Package Versions:

  • react-blockly: 8.1.1
  • blockly: 11.1.0

Thanks for the note! Does anyone know which Blockly versions import * as Blockly from 'blockly/core'; will work with? If we change over to this syntax, I want to make sure to update our React dependency version so that it will force the right upgrades for folks.

Now if you want to use this library for a new project it will crash so we need to do one of 2 options:

  1. change in package.json: "blockly": ">= 10.0.0 < 11.0.0", - but this should be temporary otherwise you freeze this version and remove all extra features from blockly core project
  2. Fix imports, I tested this, and when I changed everywhere import Blockly from 'blockly' to import * as Blockly from 'blockly/core'; seems to work fine on the "web test page" run by yarn start, but I'm not sure about imports for workspace and workspaceSVg, so I will not make PR for this now.... maybe in a few days/hours (depending on my free time)

OK, I've released two new versions of react-blockly:

  • v8.1.2 is the release with @radzikowski's PR from above. It requires a version of Blockly below 11 so that the existing imports can work.
  • v9.0.0 does the opposite: it fixes the imports to use import * as Blockly from 'blockly/core'; and supports Blockly 11, but drops support for Blockly 10.

Please upgrade to whichever version is appropriate for your project. Let me know if you run into any issues. Thanks everyone!

Both versions work well for the first run. I will try v9.0.0 more in the next few days.