-
-
Notifications
You must be signed in to change notification settings - Fork 106
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
Reference error when using without a bundler #97
Comments
We have a I have no idea how to do the same thing without Do you have any reasons to use ESM without bundler? I love ESM, but I think that even with ESM we still need bundler for performance reasons. |
Hi thanks for replying promptly.
package.exports is stable. In node, the experimental flag for this feature was removed in v12.16. Vite, webpack, rollup, web dev server, all support package.exports from sometime now
Simplify development, less tooling. Browser supports ESM by default. Agree that for large projects with hundreds of modules, bundling improves runtime performance. But in development better not bundling. See how vitejs works: no bundling in development, bundle on production As a concrete example, in the project i found the issue (first time using nanostores) https://github.com/blikblum/wc-f7 , the examples were bundled with webpack with a lot of caveats. For each example i needed a package, a webpack config, run example separated, issues importing local packages, lots of dependencies. When i migrated to web dev server things simplified a lot. BTW: this same project uses lit that makes use of package.exports to run development version |
The general We need a support on
Can you prove that it will work in all bundlers? |
As short term solution you can define: window.process = {
env: {
NODE_ENV: 'development'
}
} Before |
This is what i did: https://github.com/blikblum/wc-f7/blob/master/examples/extrouter/index.html#L14-L16
The documentation can be found at: https://nodejs.org/api/packages.html#conditional-exports Specifically at https://nodejs.org/api/packages.html#community-conditions-definitions See how lit uses https://github.com/lit/lit/blob/main/packages/lit-element/package.json#L22-L23
The main, yes: Those bundlers set development condition when in dev mode, loading the file specified in "development" key Typescript has a initial implementation https://devblogs.microsoft.com/typescript/announcing-typescript-4-5-beta/#packagejson-exports-imports-and-self-referencing not released on a stable version In this case, fallback to the file pointed in main field |
It is better to see warnings from development checks. I recommend putting What about webpack 4?
I can’t find proves that it will use package.exports.*.development` in docs. Maybe you can show tests?
It needs to change a lot in my development process. Now I have one issue from you. What if, after the changes, I got 100 issues from bundler users? Another question is how to generate these |
It has the same effect, since the check will also evaluate to true (process.env.NODE_ENV !== 'production') BTW: is better to check directly for 'development' so when no env is set or is set to a different like staging the code is not bundled
Will fallback to main field
Webpack: https://webpack.js.org/guides/package-exports/#optimizations
Although this is unlikely given the amount of work done in this spec, its always a risk
It would need do a transform (custom or with rollup). It really complicate the things a bit Finally, just leave as is and document in know issues |
We need it for
Thanks for the review. Let’s keep In a few months, I hope to start migration to |
I'm trying to use nanostores without a bundler (using https://modern-web.dev/docs/dev-server/overview/)
I'm getting Uncaught ReferenceError: process is not defined (Line https://github.com/nanostores/nanostores/blob/main/atom/index.js#L50)
This occurs because browsers do not define
process
in global scopeThe text was updated successfully, but these errors were encountered: