-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Description
What is the problem this feature will solve?
I'm the author of vite-plugin-ssr and a lot of users are having problems because many libraries ship invalid ESM code, which makes Node.js choke.
(The reason why many libraries ship erronous ESM code is because frameworks like Next.js bundle the server-side code of libraries. Where Next.js is permissive and is able to process invalid ESM code, Node.js is strict and throws an error upon invalid ESM code.)
More information at https://vite-plugin-ssr.com/broken-npm-package#solution.
This is a concern not only for vite-plugin-ssr, but also for the whole Vite ecosystem such as Nuxt and SvelteKit (see SvelteKit FAQ - How do I fix the error I'm getting trying to include a package? which is, I quote, "issues most commonly affecting SvelteKit users").
The situation is quite bad and the feedback I get from users is quite vivid, to say the least.
While one could say that it's "Next.js's fault of being permissive" (webpack more precisely speaking), the situation is what it is and it's not going to change anytime soon. So I propose following practical solution.
What is the feature you are proposing to solve the problem?
Make Node.js more permissive.
For example, a widespread problem is npm packages having invalid ESM imports, e.g. import './foo'
instead of import './foo.js'
, which makes Node.js choke. Another example is packages that ship ESM but don't have type: "module"
in their package.json
. Node.js should be able to execute npm packages that ship invalid code.
I'd make Node.js permissive only for npm packages (i.e. code living in node_modules
), while being more strict for the user land.
What alternatives have you considered?
[Edit] An alternative is to make npm validate packages before they are published: npm/rfcs#665.