Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default export #2

Closed
jer-sen opened this issue Mar 20, 2021 · 4 comments
Closed

default export #2

jer-sen opened this issue Mar 20, 2021 · 4 comments

Comments

@jer-sen
Copy link

jer-sen commented Mar 20, 2021

Could you add a default export so that isoworker as EcmaScript module can be imported (so used) from a non EcmaScript module ?

@101arrowz
Copy link
Owner

This is already done, you should be able to use the CommonJS export with a simple require call, as in:

const isoworker = require('isoworker');
isoworker.workerize(...);

// Alternatively,
const { workerize } = require('isoworker');
workerize(...);

Is this not working for you, or are you looking for some other kind of export?

@jer-sen
Copy link
Author

jer-sen commented Mar 21, 2021

Your code is ok and I think everything is fine with CommonJS.

The issue is with EcmaScript modules. In a browser or with a bundler, from a non module script, you can only import the default export of a module. The EcmaScript module version in your build should expose everything in an object as a default export.

@yuval-a
Copy link

yuval-a commented Mar 29, 2021

This is already done, you should be able to use the CommonJS export with a simple require call, as in:

const isoworker = require('isoworker');
isoworker.workerize(...);

// Alternatively,
const { workerize } = require('isoworker');
workerize(...);

Is this not working for you, or are you looking for some other kind of export?

When trying to ues require I get this error message:
Must use import to load ES Module
When trying to use the import alternatives I always get:
Cannot use import statement outside a module

@101arrowz
Copy link
Owner

package.json has a main and a module. This means both CommonJS and ESM work in bundlers and Node.js. What environment are you in where this is failing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants