Nitro not adding monorepo packages in "build" `node_modules`
Environment
Windows 11 Bun
Describe the bug
I have a monorepo with two packages:
packages/
prose/
nuxtApp/
prose package is my own custom JSX library and nuxtApp on server side is importing .jsx/.tsx files written using components of prose package.
The problem is that Nitro in build mode (in dev and generate everything works fine) is inlining my prose library in chunks directory. This is in most cases okay, but not in case of JSX, because jiti instance on server side is using prose package, not inlined data:
jiti = createJiti(ERUDIT.config.paths.project, {
fsCache: true,
moduleCache: false,
jsx: {
runtime: 'automatic',
importSource: 'prose', // Uses `prose` JSX settings, not inlined ones!
},
});
This creates errors because Symbol variables in prose package are of course not equal to inlined Symbol variables in builded Nitro app.
I tried to use nitro.externals.external to prevent inlining but it does not seem to work at all. Package is still inlined:
externals: {
inline: [],
external: [
(id) => id.includes('prose')
]
},
I tried to use nitro.rollupConfig.external function. It works BUT it completely ignores prose package and it is not stored in generated node_modules folder which means it will break if I deploy only .output/server folder without context.
rollupConfig: {
external(source, importer, isResolved) {
return source.includes('prose');
},
},
So my question — is there a way to tell Nitro to move local monorepo package to node_modules instead of inlining it or completely ignoring it?
You could try this:
externals: {
traceInclude: ['prose']
}
Not sure if it works for you, but it'd be great if you could provide a minimal reproduction. ❤️
@kricsleo Does not work unfortunately 😢
I will try to provide a minimal reproduction later.