Skip to content
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

Support Parcel 2 in WebContainers #7748

Open
rajsite opened this issue Feb 22, 2022 · 12 comments
Open

Support Parcel 2 in WebContainers #7748

rajsite opened this issue Feb 22, 2022 · 12 comments
Labels
💬 RFC Request For Comments Stale Ignore This issue is exempt from getting flagged as stale and autoremoved

Comments

@rajsite
Copy link

rajsite commented Feb 22, 2022

🙋 feature request

I'm interested in using Parcel in WebAssembly contexts such as StackBlitz WebContainers (relevant StackBlitz issue) and in the VSCode Web Extension context.

The former is to create sample projects made with parcel that are managed on GitHub and imported to stackblitz using the Import from GitHub feature. A great way to let our users get started with library and see the power of Parcel's out-of-box experience.

🤔 Expected Behavior

I can leverage Parcel in contexts where WebAssembly is the only native option.

😯 Current Behavior

Parcel fails to run in stackblitz (in the following example cli do npm run build): https://stackblitz.com/edit/parcel-2-web-container-error?file=index.ts

Have not tried but assume parcel will not run in VSCode Web Extension context as per docs linked above:

The browser runtime environment only supports the execution of JavaScript and WebAssembly. Libraries written in other programming languages need to be cross-compiled, for instance there is tooling to compile C/C++ and Rust to WebAssembly.

💁 Possible Solution

  • Add WebAsembly exeuction support
  • If Parcel does not have it on the roadmap, can look at alternatives

🔦 Context

We are creating a web component-based custom element framework and would like to encourage users to use Parcel to enabled TypeScript and SCSS usage out of the box in Vanilla / Frameworkless applications. We would like to use Stackblitz for sharing examples / issue reproduction templates. Also eyeing VSCode Web Extensions for a similar use-case via github.dev. Shoot if Parcel shipped a vscode web extension that worked in GitHub.dev that might be perfect.

💻 Examples

See above in Current Behavior.

@devongovett
Copy link
Member

We do have web assembly builds of our native modules, e.g. https://github.com/parcel-bundler/parcel/tree/v2/packages/transformers/js/wasm. They are used on https://parcel2-repl-mischnic.vercel.app/ for example. But you have to shim a whole bunch of things, like using Parcel's memory file system rather than a real one. I'm not really sure how we could make the CLI work automatically in a browser context though, because it doesn't use the wasm build and relies heavily on the file system.

@rajsite
Copy link
Author

rajsite commented Feb 23, 2022

I'm not really sure how we could make the CLI work automatically in a browser context though, because it doesn't use the wasm build and relies heavily on the file system.

Does the file I/O in the CLI happen via node.js file APIs? The StackBlitz Web Container context is a node environment. See the following quick example: https://stackblitz.com/edit/node-fileio?file=index.js

image

Or is the issue that the native modules are performing File I/O directly? If that's the case could they be compiled with WASI? Not sure if StackBlitz supports WASI in its node context yet but I imagine it could be polyfilled.

@devongovett
Copy link
Member

Both. Parcel has a FileSystem abstraction in the @parcel/fs package. We do all of our FS operations through that. There are two implementations: NodeFS and MemoryFS. The CLI always uses NodeFS. If a NodeFS is used, we make an assumption that you are using a real file system. In that case, the cache uses lmdb, which is a native C++ module. I don't believe it has a WASM build.

@FossPrime
Copy link

Logs:

$ parcel index.html courses/**/* --open
_0x5037b1 [Error]: Cannot load native addon because loading addons is disabled.
    at process.dlopen (https://node-rma527.w.staticblitz.com/blitz.5bca79c80956550a0ee18f24bf5b874e18bb8626.js:15:193771)
    at Object.Module._extensions..node (https://node-rma527.w.staticblitz.com/blitz.5bca79c80956550a0ee18f24bf5b874e18bb8626.js:6:196774)
    at Module.load (https://node-rma527.w.staticblitz.com/blitz.5bca79c80956550a0ee18f24bf5b874e18bb8626.js:6:194488)
    at Function.Module._load (https://node-rma527.w.staticblitz.com/blitz.5bca79c80956550a0ee18f24bf5b874e18bb8626.js:6:192091)
    at Module.require (https://node-rma527.w.staticblitz.com/blitz.5bca79c80956550a0ee18f24bf5b874e18bb8626.js:6:194806)
    at i (https://node-rma527.w.staticblitz.com/blitz.5bca79c80956550a0ee18f24bf5b874e18bb8626.js:6:349630)
    at _0x2ab051 (https://node-rma527.w.staticblitz.com/blitz.5bca79c80956550a0ee18f24bf5b874e18bb8626.js:15:101485)
    at Object.eval (/home/projects/node-rma527/node_modules/@parcel/source-map/parcel_sourcemap_node/index.js:15:18)
    at Object.function (https://node-rma527.w.staticblitz.com/blitz.5bca79c80956550a0ee18f24bf5b874e18bb8626.js:15:101848)
    at Module._compile (https://node-rma527.w.staticblitz.com/blitz.5bca79c80956550a0ee18f24bf5b874e18bb8626.js:6:196043) {
  code: 'ERR_DLOPEN_DISABLED'
}

🔦 Context

I'm running Stackblitz on an HP 14c. The error happens on cloud projects and on on-disk projects.

💻 Code Sample

Vanilla TS Sandbox

🌍 Your Environment

Software Version(s)
Parcel 2.3
Node 16.14
npm/Yarn 7.17
Operating System ChromeOS / Stackblitz WebContainers

@arindam89
Copy link

Is there any proposal here to make tools like parcel work in Web Containers.

@mischnic mischnic added the 💬 RFC Request For Comments label Jun 19, 2022
@mischnic mischnic changed the title Support Parcel 2 in WebAssembly Contexts Support Parcel 2 in WebContainers Jun 19, 2022
@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.

@github-actions github-actions bot added the Stale Inactive issues label Dec 16, 2022
@simonpai
Copy link

IMHO even if there's no explicit roadmap on this topic we should keep this issue open? It's a quite valuable feature.

@github-actions github-actions bot removed the Stale Inactive issues label Dec 31, 2022
@mischnic mischnic reopened this Dec 31, 2022
@nc7s
Copy link

nc7s commented May 12, 2023

In the same situation, but more surprised by parcel not having a graceful degradation that when native modules are unavailable switches to a "pure JS" implementation.

Copy link

github-actions bot commented Nov 8, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.

@github-actions github-actions bot added the Stale Inactive issues label Nov 8, 2023
@mischnic mischnic removed the Stale Inactive issues label Nov 15, 2023
@mischnic
Copy link
Member

With #9328 and #9365, if packaged/build correctly Parcel can run int he browser. The question is how we can make it use the right codepaths for WebContainers now

@GeeekyBoy
Copy link

GeeekyBoy commented Dec 13, 2023

With #9328 and #9365, if packaged/build correctly Parcel can run int he browser. The question is how we can make it use the right codepaths for WebContainers now

You can check if Parcel is running inside a WebContainer by checking if the version of the WebContainer exists as follows:

const isWebContainer = process.versions.hasOwnProperty('webcontainer');

Have I understood the problem correctly?

@github-actions github-actions bot added the Stale Inactive issues label Jun 11, 2024
@phaux
Copy link

phaux commented Jun 11, 2024

Still doesn't work out of the box on StackBlitz

@github-actions github-actions bot removed the Stale Inactive issues label Jun 11, 2024
@mischnic mischnic added the Stale Ignore This issue is exempt from getting flagged as stale and autoremoved label Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💬 RFC Request For Comments Stale Ignore This issue is exempt from getting flagged as stale and autoremoved
Projects
None yet
Development

No branches or pull requests

9 participants