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

Uncaught ReferenceError: require is not defined after upgrading to 0.5 #5546

Closed
glenjamin opened this issue Jan 31, 2024 · 7 comments
Closed
Labels
bug Something isn't working

Comments

@glenjamin
Copy link

System Info

System:
OS: Linux 5.4 Ubuntu 20.04.3 LTS (Focal Fossa)
CPU: (3) x64 Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz
Memory: 1.25 GB / 5.79 GB
Container: Yes
Shell: 5.0.17 - /bin/bash
Binaries:
Node: 18.8.0 - /usr/bin/node
Yarn: 1.22.5 - /usr/bin/yarn
npm: 8.18.0 - /usr/bin/npm
Browsers:
Chrome: 117.0.5938.132
npmPackages:
@rspack/cli: ^0.5.3 => 0.5.3
@rspack/core: ^0.5.3 => 0.5.3

Details

After upgrading to 0.5, my JS fails to load with the error

Uncaught ReferenceError: require is not defined

I've traced this down to the localforage package, this line in particualr: https://github.com/localForage/localForage/blob/1.7.3/dist/localforage.js#L7

It appears to be doing a sort of universal module definition wrapper. This works fine on webpack v5 and rspack 0.4

It likely that I'll find some workaround for this, but I wanted to report it since it's still an incompatibility

Reproduce link

https://github.com/glenjamin/rspack-localforage-repro

Reproduce Steps

  1. clone https://github.com/glenjamin/rspack-localforage-repro
  2. npm run build
  3. open the two HTML files
  4. webpack's file loads
  5. rspack's file errors
@glenjamin glenjamin added bug Something isn't working pending triage The issue/PR is currently untouched. labels Jan 31, 2024
@JSerFeng
Copy link
Contributor

JSerFeng commented Feb 1, 2024

Can you try this version
0.5.2-canary-b84638e-20240130131954

@glenjamin
Copy link
Author

I gave it a go but it's still failing with the same error in that repro repo

@Yukiniro
Copy link
Contributor

Yukiniro commented Feb 5, 2024

Same problem. Is there some solution to avoid this error.

@Yukiniro
Copy link
Contributor

Yukiniro commented Feb 5, 2024

There is a solution. Set window.require in the entry file (before import localforage from 'localforage').

window.require = window.require;

@xc2
Copy link
Collaborator

xc2 commented Feb 6, 2024

I gave it a go but it's still failing with the same error in that repro repo

@glenjamin @Yukiniro hello, i've tried 0.5.2-canary-b84638e-20240130131954 and 0.5.4 with your repro repo https://github.com/glenjamin/rspack-localforage-repro. they both work as expected. could you please have another try?

@xc2 xc2 removed the pending triage The issue/PR is currently untouched. label Feb 6, 2024
@Yukiniro
Copy link
Contributor

Yukiniro commented Feb 7, 2024

I gave it a go but it's still failing with the same error in that repro repo

@glenjamin @Yukiniro hello, i've tried 0.5.2-canary-b84638e-20240130131954 and 0.5.4 with your repro repo https://github.com/glenjamin/rspack-localforage-repro. they both work as expected. could you please have another try?

Hey, I've tried 0.5.2-canary-b84638e-20240130131954, 0.5.3 and 0.5.4. Only 0.5.3 have this problem.

@xc2
Copy link
Collaborator

xc2 commented Feb 7, 2024

I gave it a go but it's still failing with the same error in that repro repo

@glenjamin @Yukiniro hello, i've tried 0.5.2-canary-b84638e-20240130131954 and 0.5.4 with your repro repo https://github.com/glenjamin/rspack-localforage-repro. they both work as expected. could you please have another try?

Hey, I've tried 0.5.2-canary-b84638e-20240130131954, 0.5.3 and 0.5.4. Only 0.5.3 have this problem.

thank you. #5520 fixes this issue and is included in 0.5.4.

i'll close this issue then. please feel free to ask if there's any further question about the problem.

@xc2 xc2 closed this as completed Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants