Unable to resolve 'os' with ESM module dependency
See original GitHub issueBug report
This bug report relates to [this] StackOverflow question and a bug report filed on the Pisma repo: https://github.com/prisma/prisma/issues/10058
What is the current behavior?
Bundling a module made using the ESM module system with a ‘node’ protocol import does not correctly resolve ‘os’ when the package requires it.
Error: Cannot find module 'os'
at webpackEmptyContext (/home/joseph/Projects/cs-portfolio/CIS3950/agineek-website/dist/agineek-website/server/main.js:511630:10)
at ../../node_modules/.pnpm/supports-color@7.2.0/node_modules/supports-color/index.js (/home/joseph/Projects/cs-portfolio/CIS3950/agineek-website/dist/agineek-website/server/main.js:193372:15)
at __require2 (/home/joseph/Projects/cs-portfolio/CIS3950/agineek-website/dist/agineek-website/server/main.js:191265:45)
at ../../node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/index.js (/home/joseph/Projects/cs-portfolio/CIS3950/agineek-website/dist/agineek-website/server/main.js:193715:9)
at __require2 (/home/joseph/Projects/cs-portfolio/CIS3950/agineek-website/dist/agineek-website/server/main.js:191265:45)
at Object.59062 (/home/joseph/Projects/cs-portfolio/CIS3950/agineek-website/dist/agineek-website/server/main.js:231640:33)
at __webpack_require__ (/home/joseph/Projects/cs-portfolio/CIS3950/agineek-website/dist/agineek-website/server/main.js:534735:42)
at Object.76345 (/home/joseph/Projects/cs-portfolio/CIS3950/agineek-website/dist/agineek-website/server/main.js:190859:5)
at __webpack_require__ (/home/joseph/Projects/cs-portfolio/CIS3950/agineek-website/dist/agineek-website/server/main.js:534735:42)
at Object.28999 (/home/joseph/Projects/cs-portfolio/CIS3950/agineek-website/dist/agineek-website/server/main.js:191103:16) {
code: 'MODULE_NOT_FOUND'
}
The present error results from, in my case, the module prisma
which depends on supports-color
Relevant portions of the outputted bundle:
var require_supports_color2 = __commonJS2({
"../../node_modules/.pnpm/supports-color@7.2.0/node_modules/supports-color/index.js"(exports2, module2) {
"use strict";
var os2 = __require("os");
var tty = __require("tty");
var hasFlag = require_has_flag2();
var {
env
} = process;
var forceColor;
...
The issue is reported in the prisma
repo as hitting both NestJS, NextJS, and NX workspace applications.
If the current behavior is a bug, please provide the steps to reproduce.
Minimal reproduction repos:
https://github.com/quinnjr/webpack-os-error-issue
Steps to observer:
- Install dependencies and setup Prisma correctly
- Generate Prisma client
- run
npm run build:ssr
- Wait for webpack to finish bundling frontend and backend.
- Run
npm run serve:ssr
https://github.com/tonivj5/prisma-issue-10058
What is the expected behavior?
The expected behavior is for a Webpack bundle set with a node target to be able to resolve the os
module.
Other relevant information:
webpack version: v5.62.1
Node.js version: v16.13.0
Operating System: ArchLinux
Additional tools: @angular/custom-webpack
@ ^12.1.3
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (7 by maintainers)
Top GitHub Comments
@quinnjr Please read https://github.com/prisma/prisma/issues/10058#issuecomment-964117671
You need to create alias on real
os
module,{}
just create empty modules, but I think you want to useos
when you usetarget: 'node'
, try: