stackblitz / webcontainer-core

Dev environments. In your web app.
https://webcontainers.io
MIT License
3.77k stars 142 forks source link

Not allowed to load local resource -> ModuleBuildError: Module build failed -> TypeError: Failed to fetch dynamically imported module #1478

Open jantimon opened 2 months ago

jantimon commented 2 months ago

Describe the bug

When using next-yak 0.2.1 on StackBlitz, the compilation fails due to a security error preventing the loading of a local resource.

Chrome/Brave:

Not allowed to load local resource: file:///home/projects/stackblitz-starters-bp97wq/node_modules/next-yak/dist/loaders/tsloader.js

Firefox:

Security error: Content on https://stackblitzstartersbp97wq-hlff.w-corp-staticblitz.com/iframe.70dbe416.html is not allowed to load or link file:///home/projects/stackblitz-starters-bp97wq/node_modules/next-yak/dist/loaders/tsloader.js

Safari:

[Error] Cannot load file:///home/projects/stackblitz-starters-bp97wq/node_modules/next-yak/dist/loaders/tsloader.js due to access control checks.
[Error] Failed to load resource: Cross origin requests are only supported for HTTP. (tsloader.js, line 0)

The problem arises because next-yak integrates into the Next.js config and injects a webpack loader using an absolute path (e.g., /home/projects/stackblitz-starters-bp97wq/node_modules/next-yak/dist/loaders/tsloader.js).

As soon as Next.js triggers the compilation and attempts to execute the loader, it fails due to the security restrictions in StackBlitz's environment

Link to the blitz that caused the error

https://stackblitz.com/edit/stackblitz-starters-bp97wq

Steps to reproduce

  1. Open this StackBlitz project: https://stackblitz.com/edit/stackblitz-starters-bp97wq
  2. The error occurs immediately on initial page load as the compilation is triggered.

Expected behavior

The project should compile and run successfully, as it does in a local environment

Parity with Local

Screenshots

Error in Stackblitz

Platform

Browser name  = Chrome
Full version  = 126.0.0.0
Major version = 126
navigator.appName = Netscape
navigator.userAgent = Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
performance.memory = {
  "totalJSHeapSize": 273394398,
  "usedJSHeapSize": 226013986,
  "jsHeapSizeLimit": 4294705152
}
Hash = 70dbe416

Additional context

Worked before with next-yak 0.2.0: https://stackblitz.com/edit/stackblitz-starters-dfykqy?file=app%2Fpage.tsx

SamVerschueren commented 1 month ago

Hey @jantimon 👋 ! Thanks for reaching out. This looks like a bug indeed. I'll create a ticket and see what's causing this.