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

[Bug]: ReferenceError: Cannot access '__WEBPACK_DEFAULT_EXPORT__' before initialization in dev mode #2862

Closed
khangviet1996 opened this issue Jul 10, 2024 · 7 comments
Labels
🐞 bug Something isn't working

Comments

@khangviet1996
Copy link

khangviet1996 commented Jul 10, 2024

Version

System:
    OS: Windows 10 10.0.19045
    CPU: (16) x64 Intel(R) Core(TM) i7-10700 CPU @ 2.90GHz
    Memory: 7.82 GB / 31.87 GB
  Browsers:
    Chrome: 126.0.6478.127
    Edge: Chromium (126.0.2592.87)
    Internet Explorer: 11.0.19041.4355
  Packages: rsbuild 1.0.0-alpha.6 and 1.0.0-alpha.7

Details

image
image

I'm facing an issue in development mode where everything works fine in version v7.0.10 and in build mode in the latest version. Essentially, index.js acts as a barrel file:

import User from './avatar/User';
import UserOptions from './menu/UserOptions';
import HeaderOpenItem from './headerOpenItem/HeaderOpenItem';
import MeetingNotification from './menu/MeetingNotification';

export const UserAvatar = User;
export const UserMenu = UserOptions;

export { HeaderOpenItem, MeetingNotification };

I don't know the reason for the issue yet, so I can't provide more details at the moment. I'll add more information once I identify the cause.

Reproduce link

no produce

Reproduce Steps

pnpm run dev

@khangviet1996 khangviet1996 added the 🐞 bug Something isn't working label Jul 10, 2024
@SoonIter
Copy link
Member

related to web-infra-dev/rspack#6861

Could you try to turn on this configuration?

// rsbuild.config.ts
tools: {
	rspack: {
		output: {
			environment: {
				const: false
			}
		}
	}
}

If this does not solve this issue, please provide a reproduction repository.

@khangviet1996
Copy link
Author

Thank you so much!

@chenjiahan
Copy link
Member

Is this error expected to be happen?

@ahabhgk can you check this

@ahabhgk
Copy link
Contributor

ahabhgk commented Jul 10, 2024

Could you provide a minimal reproduce so I can debug further to fix the root issue here

@chenjiahan chenjiahan reopened this Jul 10, 2024
@khangviet1996
Copy link
Author

Could you provide a minimal reproduce so I can debug further to fix the root issue here

This is my company's private project, so I'll debug and create a minimal reproduction. However, after adding the following configuration:
But added tools: { rspack: { output: { environment: { const: false } } } },
everything seems fine
Thank you so much!

@chenjiahan
Copy link
Member

I will close this issue due to lack of reproduction. If anyone encountered the same issue, providing a reproduction will be very helpful for debugging.

@SoonIter
Copy link
Member

SoonIter commented Jul 29, 2024

This problem is due to circular references, and it is not a rspack/webpack issue.

In dev, output.environment.const = true, so this error message will only appear during development.

Summary

output.environment.const = false

This configuration will hide some potential runtime errors in the case of circular references.

We should try our best to use output.environment.const = true and repair circular references at development time, output.environment.const = false can be used in an emergency.

some details and reproduction

https://github.com/SoonIter/circular-reference-rspack

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