neutralinojs / neutralino.js

JavaScript API for Neutralinojs

Home Page:https://neutralino.js.org/docs/api/overview

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build fails with "Attempted import error" after updating `@neutrolinojs/lib` to 5.1.0

jeffwtm opened this issue · comments

I'm experiencing a build failure after updating @neutrolinojs/lib to 5.1.0:

Failed to compile.

Attempted import error: 'filesystem' is not exported from '@neutralinojs/lib' (imported as 'filesystem').

Steps to repro:

  1. Create new app using neu create myapp --template codezri/neutralinojs-react (as specified here: https://neutralino.js.org/docs/getting-started/using-frontend-libraries)
  2. cd to myapp/react-src
  3. Update @neutrolinjs/lib by running npm install @neutralinojs/lib@5.1.0 (as specified here: https://github.com/neutralinojs/neutralino.js/releases/tag/v5.1.0)
  4. Attempt to build: npm run build from react-src or neu build from myapp directory

I've also tried this in a pre-existing project with TypeScript and gotten the same result. Strangely, running tsc directly compiles without errors in that project, but running the build script fails with the same "Attempted import error".

Let me know if there's any other info I can provide, and thank you!

Neu cli v 11.0.1
macOS 14.0
Node 18.20.2

Seems to work okay when I downgrade to @neutralinojs/lib@5.0.1

Seems to work okay when I downgrade to @neutralinojs/lib@5.0.1

Or maybe not... I don't get the typescript-related error, but I'm seeing errors in the devtools console of the running app.

commented

I faced the same issue while following the Using any frontend library guide and decided to do some digging.

I'm using neutralino version 5.1.0, and was able to get rid of the problem by explicitly importing the function as the following:
import { filesystem } from "@neutralinojs/lib/dist/neutralino"
Of course, if you follow the guide, you'll eventually encounter the same issue with the init function. Again, I was able to get it working by explicitly importing the function as:
import { init } from "@neutralinojs/lib/dist/neutralino";
So that is a quick fix.

Now, my knowledge is not particularly strong in the Javascript ecosystem mess, so I'm putting here my findings. Hopefully somebody could provide some expertise on what could be the actual issue. As a use-case, I'll be talking in the context of the init function.
Looking into the neutralino package sources, it's @neutralinojs/lib/package.json specifies the main entry to be @neutralinojs/lib/dist/index.js:

{
  ...some stuff...
  "main": "./dist/index.js",
  ...other stuff...
}

The init function is exported in CommonJS format there:

exports.init=function(t={}){if(t=Object.assign({exportCustomMethods:!0}, ..etc...

As oposed to @neutralinojs/lib/dist/neutralino.d.mts (or @neutralinojs/lib/dist/neutralino.mjs), where the function is exported in the ESM format:

export { ...some stuff..., init, ...other stuff... }

So, it seems like letting npm to explicitly use EMS-exported functions works, although to my knowledge it should work either way.