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

REPL: importing 'svelte' returns undefined #299

Open
Conduitry opened this issue May 25, 2018 · 4 comments
Open

REPL: importing 'svelte' returns undefined #299

Conduitry opened this issue May 25, 2018 · 4 comments

Comments

@Conduitry
Copy link
Member

https://svelte.technology/repl?version=2.6.4&gist=29c93c880013a472c3b079afaa720c2a

The above code works if you download a .zip and run it locally, but in the REPL, after import svelte from 'svelte', svelte is undefined. The inner workings of the REPL's module resolution and bundling are a little mysterious to me, but evidently something is getting confused when importing 'svelte'.

cc @burningTyger

@Conduitry
Copy link
Member Author

Conduitry commented Jun 8, 2018

Taking a peek at this. This is most peculiar - curl(['https://bundle.run/svelte']) is returning (a promise resolving to) undefined, instead of the module.

If I run

curl.config({ dontAddFileExt: /./ });
curl(['https://bundle.run/svelte']).then(_ => console.log(_))

completely separately from svelte.technology or the REPL, I see the same thing. So it looks like this is an issue with curl.js (or with how packd is bundling svelte?) and not with the REPL.

@Conduitry
Copy link
Member Author

Conduitry commented Jun 8, 2018

Just including a script tag on a page pointing to 'https://bundle.run/svelte' fails to set window.svelte so I'm thinking this is more likely to be an issue with packd.

Edit: Or maybe Svelte's package.json ought to have a module entry pointing at an ES module build? packd should still be able to handle a commonjs module though.

@Rich-Harris
Copy link
Member

Huh. This is actually Rollup's fault, in a way, since it's taking the UMD build from the Svelte package and wrapping that in another UMD build, which would work fine except that it's rewriting this to undefined, per the ESM spec. Adding a pkg.module would be the easiest way to fix this specific case.

@Conduitry
Copy link
Member Author

Interesting. What is packd doing exactly when it is asked to deal with a package with no ES module field? I'm a bit surprised that https://github.com/Rich-Harris/packd/blob/master/package.json doesn't mention rollup-plugin-commonjs. Something has to be happening before Rollup gets the module, because the module isn't an ES6 module and Rollup isn't complaining about it. Rollup treating a top-level this as undefined doesn't really seem like a problem to me - that should be getting handled by someone else, right?

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

2 participants