question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't resolve standard node library if require includes '/' (slash)

See original GitHub issue

Bug report

What is the current behavior?

doesnt_work.js:

require('util/types');

The command below: node_modules/.bin/webpack --target=node --entry ./doesnt_work.js

throws Module not found: Error: Can't resolve 'util/types' in '/Users/pbadenski/workspace/test'

Note: It works fine if require doesn’t contain slash ie. require('util').types

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

doesnt_work.js:

require('util/types');

node_modules/.bin/webpack --target=node --entry ./doesnt_work.js

What is the expected behavior?

Running webpack doesnt_work.js should resolve util/types successfully as NodeJS documentation says API is accessible via require('util').types or require('util/types'). (https://nodejs.org/api/util.html#utiltypes)

Other relevant information: webpack version: 5.68.0 Node.js version: v17.1.0 Operating System: MacOS 11.6.2 (20G314)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
vankopcommented, Feb 14, 2022

@sibelius currently in master. next release will be on this week probably…

0reactions
sibeliuscommented, Feb 14, 2022

is this fixed in which wepback version?

Read more comments on GitHub >

github_iconTop Results From Across the Web

NPM global install "cannot find module" - node.js
My script fails on require('promised-io/promise') : [neek@uberneek project]$ node buildscripts/stringsmerge.js module.js:340 throw err; ^ Error: Cannot find ...
Read more >
CommonJS modules | Node.js v19.3.0 Documentation
When a file is run directly from Node.js, require.main is set to its module . That means that it is possible to determine...
Read more >
Troubleshooting Node.js Deploys - Heroku Dev Center
Fix this case by moving the slash to the front, which will only match the lib directory in the application root directory. /lib....
Read more >
API - ESBuild
In node, you can load a module using node --experimental-modules file.mjs . Note that node requires the .mjs extension unless you have configured...
Read more >
Module | webpack - JS.ORG
If you supply a Rule.include option, you cannot also supply a Rule.resource . ... node: false, // disable __dirname, __filename, module, require.extensions ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found