Skip to content

Make it compatible with Node's ESM imports. #4806

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

Closed
navaru opened this issue May 8, 2020 · 5 comments
Closed

Make it compatible with Node's ESM imports. #4806

navaru opened this issue May 8, 2020 · 5 comments
Labels
awaiting submitter needs a reproduction, or clarification

Comments

@navaru
Copy link

navaru commented May 8, 2020

Currently if I run a compiled svelte app in esm format on node for SSR I get the following error:

node --experimental-modules --experimental-json-modules --es-module-specifier-resolution=node svelte.app.mjs (node v14)

import { create_ssr_component } from 'svelte/internal';
         ^^^^^^^^^^^^^^^^^^^^
SyntaxError: The requested module 'svelte/internal' does not provide an export named 'create_ssr_component'

To fix that issue I added type: "module" to node_modules/svelte/package.json, but the svelte/compiler is compiled in umd format and throws an error:

import compiler from "svelte/compiler";
       ^^^^^^^^
SyntaxError: The requested module 'svelte/compiler' does not provide an export named 'default'

Can we change how svelte/compiler is built, to something similar to svelte/internal?

@AlbertMarashi
Copy link

Would adding
type: "module" break it for people below node 13?

@navaru
Copy link
Author

navaru commented May 19, 2020

Starting with Node v12 if the file ending is .js it will search for the nearest package.json and look for the "type": "module" field and load it as an ES module.

I could dig in to see how we can make it work, but I need to know if we can also change how the svelte/compiler is built.

@Pierstoval
Copy link
Contributor

Pierstoval commented Jun 4, 2020

Not sure what to do, but there's also an issue when fetching the package via Pika, mostly when using Deno.

If I have code like this:

import compile from 'https://cdn.pika.dev/svelte@^3.23.0';

There is an issue when resolving files and types:

error: relative import path "svelte/internal" not prefixed with / or ./ or ../ Imported from "https://cdn.pika.dev/-/[email protected]/dist=es2019,mode=types/types/runtime/ambient.d.ts"

I tried to allow exporting the compiler to ESM via #4972 , and when I do this on my machine and import {compile} from './compiler.mjs';, it works as expected. Only the frontend-side module doesn't work yet because of the same svelte/internal issue, I don't know (yet) how to fix it.

@Conduitry Conduitry added the awaiting submitter needs a reproduction, or clarification label Jun 8, 2020
@slightlyfaulty
Copy link

This is also an issue with Webpack 5. Because it now follows strict ESM import rules, you get a bunch of errors from Svelte imports like this:

ERROR in ../../node_modules/svelte/easing/index.mjs 1:0-49
Module not found: Error: Can't resolve '../internal' in '.../node_modules/svelte/easing'
Did you mean 'index.mjs'?
BREAKING CHANGE: The request '../internal' failed to resolve only because it was resolved as fully specified
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.

Currently to get Svelte to work in Webpack 5 you have to completely disable strict ESM imports.

@dummdidumm
Copy link
Member

Svelte provides the exports field now so this should be resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting submitter needs a reproduction, or clarification
Projects
None yet
Development

No branches or pull requests

8 participants