Turbopack has trouble with `.cjs` files inside esm build
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
I guess this issue has similar root cause as https://github.com/dahlia/logtape/issues/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 https://github.com/dahlia/logtape/blob/327c94738fa8375796acfe9fd4973576633fa1c3/logtape/fs.ts#L12 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.
Could you try v0.9.0-dev.133?
@dahlia , error is still present
@mkatrenik What sinks do you use? Could you share your configuration?
await configure({
sinks: {
console: getConsoleSink({
formatter: getAnsiColorFormatter({
categoryStyle: 'bold',
categoryColor: 'magenta',
format({ timestamp, level, category, message, record }) {
const showProperties = env.LOG_SHOW_PROPERTIES === true;
const properties =
showProperties && Object.keys(record.properties).length > 0
? `\n${util.inspect(record.properties)}`
: '';
return `${timestamp} ${level} ${category}: ${message}${properties}`;
},
}),
}),
},
loggers: [
{
category: ['logtape', 'meta'],
sinks: [],
},
{
category: 'next-app',
level: 'info',
sinks: ['console'],
},
{
category: 'common',
level: 'info',
sinks: ['console'],
},
],
});
Hmm, unable to reproduce. Could you let me know what version of Next.js you use?
The latest unstable release @logtape/[email protected] revamped the whole bundling configuration. Could you give it a try?
@dahlia error is gone!