Giter Site home page Giter Site logo

Comments (9)

JayaKrishnaNamburu avatar JayaKrishnaNamburu commented on May 19, 2024 1

So, i spent some time around this. And here are some of the observations. This should be handled in many ways, but the first solution is the best way to do it imo.

Solution

First @codesandbox/codesandbox-client is using process and it's a pure node thing. Which is being polyfilled by bundlers all these years, but from webpack~5 the node built-ins are not polyfilled anymore. So,

  • Any packages that target browser shouldn't use process inside them. If they still do so, it's good to remove it in build or anything shipped to npm. And as i see currently sandpack is just transpiling and not doing a build.
  • If the usage is mandatory, then the process needs to be polyfilled by the library and so people who consumes it don't need to do it again on their side. (But if every package stat's doing it, then we have node-polyfiils duplicated everywhere in the end build). So, the best way is to remove process from the end build.

I tried making the existing 0.0.6 work. But here the hurdles.

So, currently these are all the things, if process/browser resolves in lezer esm. Then docusaurus-node-polyfills unblocks the webpack error.

Here is the fork of the example above
https://github.com/JayaKrishnaNamburu/sandpack-docusaurus-test/blob/trail/node-polyfill/docusaurus.config.js
https://github.com/JayaKrishnaNamburu/sandpack-docusaurus-test/blob/trail/node-polyfill/package.json#L20

Docusaurus plugin for polyfills
https://github.com/JayaKrishnaNamburu/docusaurus-node-polyfills

from sandpack.

alexnm avatar alexnm commented on May 19, 2024 1

wow, nice research @JayaKrishnaNamburu! thanks for taking the time!

On our side we can remove the usage of process in sandpack-client and rely on props when setting up storybook or anything else to run with a local bundler, but we would still have the issue from codemirror I guess.

from sandpack.

JayaKrishnaNamburu avatar JayaKrishnaNamburu commented on May 19, 2024 1

Here is a update, I have the working repo here https://github.com/JayaKrishnaNamburu/sandpack-docusaurus-test/tree/trail/node-polyfill

Just added a new package docusaurus-node-polyfills which i just released by wrapping up the changes https://github.com/JayaKrishnaNamburu/docusaurus-node-polyfills

from sandpack.

alexnm avatar alexnm commented on May 19, 2024

this is strange, feels like the error is coming from this line: https://github.com/codesandbox/sandpack/blob/main/sandpack-client/src/client.ts#L91 but that should be solved by the bundler?! Not familiar with docusaurus, this happens at build time?

from sandpack.

JayaKrishnaNamburu avatar JayaKrishnaNamburu commented on May 19, 2024

Yes, the issue still exists with codemirror. Unfortunately, we will run into such issues unless the browser targeted libraries stop using process in end build 😅. So, now only two things left

  • Either this PR get's merged and this plugin upgrades it.
  • Or just write the fallback in the plugin directly since it's a small change. I will see today if i can write the fallback in the docusaurus plugin itself :)

from sandpack.

alexnm avatar alexnm commented on May 19, 2024

Unfortunately, we will run into such issues unless the browser targeted libraries stop using process in end build 😅

I feel like this is almost impossible, since a lot of libraries rely on env variables, even just for checking NODE_ENV

from sandpack.

JayaKrishnaNamburu avatar JayaKrishnaNamburu commented on May 19, 2024

Yes, yes. So, for the moment polyfilling is the right way to solve those problems. Unless web standards come up with something for in browsers 😄

from sandpack.

pomber avatar pomber commented on May 19, 2024

None of my use cases use the editor, I use sandpack for running the preview, so I don't need codemirror. Not sure how often other people use/will use sandpack without the editor, but have you considered having the preview runner in its own separated package?

from sandpack.

danilowoz avatar danilowoz commented on May 19, 2024

Hey, we believe that this issue has been solved in the latest release (v0.1.13); please let me know if this bug still persists.

Thanks for reporting it!

from sandpack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.