Replies: 2 comments 3 replies
-
I solved this with a webpack plugin: class NextEntryPlugin {
apply(compiler) {
compiler.hooks.afterEnvironment.tap("NextEntryPlugin", () => {
compiler.options.resolve.conditionNames.unshift("next");
compiler.options.resolve.mainFields.unshift("next");
});
}
} |
Beta Was this translation helpful? Give feedback.
-
@timneutkens Would it be possible to turn this discussion into an issue? I would expect So if I define: "compilerOptions": {
"customConditions": ["snaplet_development"]
} I would expect Next.js to match this condition when resolving the external packages. And even better, if the external package is detected as a Typescript project reference, I would also expect Next.js to pick-up the external package's own Those are the two things I'm missing to make Next.js great in TypeScript monorepos. |
Beta Was this translation helpful? Give feedback.
-
Question: Does Next.js support custom entries in the package.json exports field?
Usecase:
In a monorepo that contains a component package, I've got some custom entries defined for various tools and environments. So far every tool respected the custom entires and everything worked smoothly. But in the case of Next.js I'm not able to force it to use the custom
next
entry, it always tries to read the"."
or".": { "import": "..." }
which in my case ends up in an error messageModule not found: Package path . is not exported from package ...
.Solutions tried:
resolve.conditionNames = ['next']
to the weback configuration innext.config.js
[1]"dev": "NODE_OPTIONS='--conditions=next' next dev"
[2][1] https://webpack.js.org/configuration/resolve/#resolveconditionnames
[2] https://nodejs.org/api/packages.html#resolving-user-conditions
Example:
Exports field defined in component package.json
Beta Was this translation helpful? Give feedback.
All reactions