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
ES module browser build expects "process" global #237
Comments
@guybedford can you send PR with |
process.env.NODE_ENV will never be reached because of |
@TrySound to be super clear here, while |
As a temporary solution you can use |
@ai the problelm is a dependency of a dependency importing |
Let’s create an issue in jspm to add |
@ai the problem is that |
Only when using CommonJS will jspm support the |
@guybedford do you see any other option on how to keep good DX and support browser API? I am suggesting changing jspm because I do not see other options. |
@ai I'm not sure why the original form of this PR to add |
Because webpack doesn't add if (typeof process !== "undefined" && process.env.NODE_ENV === "development") { Will be compiled to: if (typeof process !== "undefined" && "development" === "development") { Since browser do not have |
I see, that makes sense. I think the root issue here is that you're taking an ES module designed to match CommonJS module semantics for Webpack semantics, then stating it to be the browser entry point when it simply isn't a native browser module at all. I would suggest authoring a native browser module directly that fits the requirements of the browser, rather than starting from the above constraint. |
Alternatively, simply removing the |
We need to separate Node.js and browser file, because they have a different crypto API Why adding Even if we will fix Nano ID we will have many and many npm modules with |
Many of us are actively working towards workflows where the If such a module now expects arbitrary globals to exist in the host environment that don't otherwise exist, then you need a build step. Certainly many are on the side of living with builds in JS for any package loaded, and perhaps that is the philosophical difference here. But jspm stands firmly on the native platform module side and won't budge on that. |
We will need some kind of build step for performance reasons. Every for pure ESM code we will need:
I like the idea of a revolution for good ideas. But my experience tells me that there are two kinds of revolutions:
In my experience, the first type of revolutions fail. How we will be able to create a new world by ignoring all content of the npm? Why do we need jspm build-on-the-fly CDN if it does not allow us to use npm library in ESM projects? Do you remember Python 2→3 revolutions with compatibility drop? They still didn’t end this migration. If we will use only pure solutions, ESM will not survive and migration to ESM will take decades for the community. There are many use cases when we want to keep the production bundle from unnecessary development checks. There are plenty of development-only checks in React. In Nano ID that We need some way to do it. And more important, that we need a way to convert all packages. |
jspm as a project builds significantly on the ability to allow users to load any package from npm with full npm CommonJS and semantic compatibility in a way that requires no build. There are a lot of deep details around how it handles package optimization, treeshaking, import maps and preloading generation which I can't go into in a GitHub comment. If you're interested in discussing this side of things further I'm always happy to chat. That all to say that most of the work is exactly about building ecosystem bridges here. From SystemJS to Node.js modules. Python 2-3 comes up a lot in Node.js modules discussion, I like to think we avoided those biggest issues in having a full compatibility story. As for the issue at hand there are a few main points:
Unfortunately for the I was thinking about this some more though and I think it can work with the separate {
"exports": {
"browser": {
"production": "./index.browser.js",
"default": "./index.browser.development.js"
},
"require": "./index.cjs",
"import": "./index.js"
}
} With the pattern in https://github.com/guybedford/nanoid/blob/patch-1/index.browser.development.js. If you would be open to that I would be glad to reopen the PR - let me know? I just couldn't see where you are populating the "exports" field though through dual-publish. For (3) I think it would be useful to have further discussion here on this topic. The definition of the I think naturally any package that wants to support the browser will smooth these things out over time. The more we can remove the implicit weird vestigal assumption from the new modern workflows we are creating the better, but I will certainly concede on compat arguments if the main river goes that way, but we still have time on this specific convention to see which way things go. |
Yeap. Send a PR with an another way to avoid development checks in production bundle. I like |
Sure, I've created a tracking issue in dual-publish for this at ai/dual-publish#14. |
I released 3.1.17 with new Does it work in your case? |
Looks great, and its working perfectly with jspm now thanks. |
@guybedford how do you test it with |
The local installer is still in private beta so isn't available for testing yet. When it is, a local test run would be possible. In the mean time for post-publish testing |
I need some tool to test unreleased packages. OK, feel free to ping me on any regressions with |
@guybedford oops, seems like jspm takes Look at |
Yes, the If you are interested in trying it out locally, the private beta is open to anyone - you can request an invite from Discord here https://discord.com/invite/dNRweUu. |
When running this package on jspm, it will give "process is undefined" because of the process check in the index.browser.js file.
The assumption of the browser environment shouldn't be based on the proces global existing. Adding a
typeof process !== 'undefined'
check would fix this issue.The text was updated successfully, but these errors were encountered: