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

Can't import JS files with normal ESM syntax inside components #46

Closed
matthew-ia opened this issue Jan 2, 2022 · 3 comments · Fixed by #59
Closed

Can't import JS files with normal ESM syntax inside components #46

matthew-ia opened this issue Jan 2, 2022 · 3 comments · Fixed by #59
Labels
bug Something isn't working

Comments

@matthew-ia
Copy link
Owner

Pretty sure this another bug related to svelte/register.

E.g., this throws an error:

Error [ERR_REQUIRE_ESM]: require() of ES Module not supported.
(code: 'ERR_REQUIRE_ESM')

which doesn't make sense, because we're not using require().

import { some } from 'file.js';
@matthew-ia matthew-ia added the bug Something isn't working label Jan 2, 2022
@matthew-ia
Copy link
Owner Author

matthew-ia commented Jan 2, 2022

This is the only workaround I've found, using import(), which is a suggestion in the error report:

let look = {};
import('../js/Looks.js').then((m)=>{
  const Looks = m.default;
  look = new Looks();
});

@matthew-ia
Copy link
Owner Author

matthew-ia commented Jan 5, 2022

import() fix doesn't work bc it's async. Use CJS. This is actually a known limitation of svelte/register, but can't be fixed for now. Also consider this comment re: svelte/reigster from the penguin.

const some = require('../some.js').default;

Almost require doesn't work in normal Svelte land but it works fine for register. All I had to do was read the error a few more times.

Also means file being imported needs .cjs extension and to use CJS import/export syntax, i.e., export default ... goes to exports.default = ...

@matthew-ia
Copy link
Owner Author

This will likely and hopefully be fixed when the full fix for #42 is resolved.

matthew-ia added a commit that referenced this issue Oct 5, 2022
…ss (#59)

This compilation (bundling) is uses rollup instead of the Svelte API directly (`svelte/compile` and `svelte/preprocess`), as this was initially going to use. 

---

### Fixes: 
- fix #50 
- fix #49
- fix #47
- fix #46
- fix #44
- fix #58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant