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

Can't resolve node builtin modules in esm build dependency #15574

Closed
keenwon opened this issue Mar 22, 2022 · 10 comments · Fixed by #15577
Closed

Can't resolve node builtin modules in esm build dependency #15574

keenwon opened this issue Mar 22, 2022 · 10 comments · Fixed by #15577
Labels

Comments

@keenwon
Copy link

keenwon commented Mar 22, 2022

Bug report

What is the current behavior?

<w> [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Can't resolve 'url' in '/Users/keenwon/Test/webpack-test'
<w> while resolving 'url' in /Users/keenwon/Test/webpack-test as file
<w>  at resolve esm file url
<w>  at file dependencies /Users/keenwon/Test/webpack-test/webpack.config.mjs
<w>  at file /Users/keenwon/Test/webpack-test/webpack.config.mjs
<w>  at resolve commonjs /Users/keenwon/Test/webpack-test/webpack.config.mjs

If the current behavior is a bug, please provide the steps to reproduce.

works fine, no warnings

What is the expected behavior?

Other relevant information:
webpack version: 5.70.0
Node.js version: v14.19.0
Operating System: macOS 12.3
Additional tools:

demo

repo https://github.com/keenwon/webpack-test, switch to node-prefix branch

image

node: doesn't work either

image

@alexander-akait
Copy link
Member

Duplicate #14166

@alexander-akait
Copy link
Member

Please use #14166 (comment)

@vankop vankop closed this as completed Mar 22, 2022
@keenwon
Copy link
Author

keenwon commented Mar 23, 2022

@alexander-akait @vankop
not work, I use node:url or url in webpack.config.mjs

In other mjs files, it works

// test.mjs
import path from 'node:path'
console.log(path.dirname('/foo/bar/baz/asdf/quux'))

@vankop
Copy link
Member

vankop commented Mar 23, 2022

your config should be

externals: { 'node:X': 'commonjs2 X' }

where X is used module (url, path etc)

@keenwon
Copy link
Author

keenwon commented Mar 23, 2022

I have committed to the node-prefix branch(repo)

image

image

@vankop
Copy link
Member

vankop commented Mar 23, 2022

ok, I understand what you are doing.. please use url and path modules in webpack.config.. (without node: prefix)

settings with externals works only for bundling code, not webpack config..

@keenwon
Copy link
Author

keenwon commented Mar 23, 2022

Yes, that's the weird part. the url also not works

(Please see the first picture of this issue)

@vankop
Copy link
Member

vankop commented Mar 23, 2022

I found a problem.. For now I can suggest to use commonjs config format..

@vankop vankop reopened this Mar 23, 2022
@vankop vankop changed the title Can't resolve node builtin modules Can't resolve node builtin modules in esm build dependency Mar 23, 2022
@sokra sokra reopened this Mar 28, 2022
@webpack-bot
Copy link
Contributor

This issue had no activity for at least three months.

It's subject to automatic issue closing if there is no activity in the next 15 days.

@vankop
Copy link
Member

vankop commented Aug 2, 2022

solved in #15611

@vankop vankop closed this as completed Aug 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants