Code Monkey home page Code Monkey logo

Comments (4)

xan105 avatar xan105 commented on September 20, 2024

Yes, dynamic import: await import('...') is the only way I know of.
Have to make it a dual CJS/ESM package for your use case (?).

Would changing all of the exports from

{
  ".": {
     "types": "./types/index.d.ts",
     "default": "./lib/index.js"
  },
  ...
}

to

{
  ".": {
     "require": "./lib/index.cjs",
     "import": "./lib/index.js",
     "types": "./types/index.d.ts"
  },
  ...
}

be enough for vite ? Bundler wise I only know some esbuild.
If so I'll try to remember how to CJS and add it to the generate exports script.

(I went all-in when esm was available, I haven't used CJS in years).

from node-nodert.

xan105 avatar xan105 commented on September 20, 2024

πŸ€”Is this https://nodejs.org/api/vm.html#when-importmoduledynamically-is-a-function related to your problem ?

When importModuleDynamically is a function, it will be invoked when import() is called in the compiled code for users to customize how the requested module should be compiled and evaluated. Currently, the Node.js instance must be launched with the --experimental-vm-modules flag for this option to work. If the flag isn't set, this callback will be ignored. If the code evaluated actually calls to import(), the result will reject with ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG.

Node arg can be passed to electron using --js-flags="foo=bar"
ex: electron --js-flags="--env-file=.env" .

from node-nodert.

ShafSpecs avatar ShafSpecs commented on September 20, 2024

πŸ€”Is this https://nodejs.org/api/vm.html#when-importmoduledynamically-is-a-function related to your problem ?

When importModuleDynamically is a function, it will be invoked when import() is called in the compiled code for users to customize how the requested module should be compiled and evaluated. Currently, the Node.js instance must be launched with the --experimental-vm-modules flag for this option to work. If the flag isn't set, this callback will be ignored. If the code evaluated actually calls to import(), the result will reject with ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG.

Node arg can be passed to electron using --js-flags="foo=bar" ex: electron --js-flags="--env-file=.env" .

Seems like it is the issue. πŸ€”, I am wondering how I can now append this flag to my production executable so that it always get run. The package doesn't seem like it would be receiving updates anymore so it would always be experimental.

Or I just remove the bytecode protection and see how that goes

Edit: Passing the flag didn't seem to fix the issue. Passed it multiple ways, via the bytecode loader, script itself, electron switches and more. But it didn't work. Such a shame that node leaves their work in shambles atimes πŸ˜…

from node-nodert.

ShafSpecs avatar ShafSpecs commented on September 20, 2024

Looking at: https://nodejs.org/docs/latest-v21.x/api/vm.html#vmconstantsuse_main_context_default_loader, this should solve the issue. Except node 21.7.3 throws undefined error, this is a real headscratcher and atp out of the scope of this project. Thanks Anthony πŸ‘‹

from node-nodert.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.