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

[Feature Request]: non_webpack_require #2408

Closed
ScriptedAlchemy opened this issue Mar 22, 2023 · 10 comments · Fixed by #4175
Closed

[Feature Request]: non_webpack_require #2408

ScriptedAlchemy opened this issue Mar 22, 2023 · 10 comments · Fixed by #4175
Assignees
Labels
feat New feature or request

Comments

@ScriptedAlchemy
Copy link
Contributor

ScriptedAlchemy commented Mar 22, 2023

What problem does this feature solve?

This allows me to skip bundling a specific require call. __non_webpack_require__ is converted back into require and is often used inside libraries as a way to escape the containers closure.

This is the same concept as webpack magic comments for webpackIgnore on a import(), which tells webpack to use native import() spec to load that specific file. For require or sync imports - non_webpack_require does the same kind of thing

What does the proposed API of configuration look like?

this is syntax sugar, no outward facing api.

I believe this would be a parser update or require factory alteration to match how webpack does it currently.

@ScriptedAlchemy ScriptedAlchemy added the feat New feature or request label Mar 22, 2023
@hardfist hardfist added this to the backlog milestone Mar 22, 2023
@hardfist
Copy link
Contributor

we should support it but you can workaround it by eval('require')(id)

@ScriptedAlchemy
Copy link
Contributor Author

Just to note for users reading, libraries may have issues till this is patched if they depend on breaking out of webpack with non require.

@stale
Copy link

stale bot commented Jul 15, 2023

This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

@stale stale bot added the stale label Jul 15, 2023
@Ttou
Copy link

Ttou commented Aug 18, 2023

we should support it but you can workaround it by eval('require')(id)

how to do?use rspack to start nestjs project,output error

image

@stale stale bot removed the stale label Aug 18, 2023
@hardfist
Copy link
Contributor

where do you use the __non_webpack_require api? can yo paste the coe

@Ttou
Copy link

Ttou commented Aug 18, 2023

the package app-root-path has use this api

// node_modules/app-root-path/lib/resolve.js

//...
// If we're in webpack, force it to use the original require() method
var requireFunction = ("function" === typeof __webpack_require__ || "function" === typeof __non_webpack_require__)
	? __non_webpack_require__
	: require;
// ...

@hardfist
Copy link
Contributor

so you use some third-party module which use __no_webpack_require__ api?

@Ttou
Copy link

Ttou commented Aug 18, 2023

yes

@hardfist
Copy link
Contributor

you either wait for rspack no_webpack_require implementation or use patch-package to modify third party mode code

@NexxLuo
Copy link

NexxLuo commented Apr 15, 2024

when i use non_webpack_require, an error occurs :require is not defined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants