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

Turbopack has trouble with .cjs files inside esm build #27

Open
mkatrenik opened this issue Nov 27, 2024 · 1 comment
Open

Turbopack has trouble with .cjs files inside esm build #27

mkatrenik opened this issue Nov 27, 2024 · 1 comment

Comments

@mkatrenik
Copy link

turbopack has trouble with .cjs files inside esm build

│ Import trace for requested module:
│ ../../node_modules/@logtape/logtape/esm/nodeUtil.cjs
│ ../../node_modules/@logtape/logtape/esm/nodeUtil.js
│ ../../node_modules/@logtape/logtape/esm/formatter.js
│ ../../node_modules/@logtape/logtape/esm/mod.js
│ ./src/lib/logger.ts
│ ./src/app/layout.tsx
│  ⚠ ../../node_modules/@logtape/logtape/esm/fs.cjs
│ Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
│ 
│ ../../node_modules/@logtape/logtape/esm/nodeUtil.cjs
│ Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
@kachkaev
Copy link

kachkaev commented Dec 19, 2024

I guess this issue has similar root cause as #19. If we import { **everything** } from '@logtape/logtape';, each export has to be compatible with all environments (Node, Deno, Browser, edge, bundlers, etc.). Dependencies like require("node:fs") are quite hard to mask so that they are only used when needed. Something like this would work without hacks:

import { something, agnostic, to, runtime, environments } from '@logtape/logtape';
import { somethingSpecificToFoo } from '@logtape/logtape/foo';
import { somethingSpecificToBar } from '@logtape/logtape/bar';

The problem with environment-specific hacks like

fs = await import("node" + ":fs");

is that they are not robust long-term. Even if there are no known issues reported at the moment, the situation may degrade with a change in some bundler at any time.

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

No branches or pull requests

2 participants