nitro icon indicating copy to clipboard operation
nitro copied to clipboard

Nitro not adding monorepo packages in "build" `node_modules`

Open Gwynerva opened this issue 3 months ago • 2 comments

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?

Gwynerva avatar Sep 09 '25 06:09 Gwynerva

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 avatar Sep 13 '25 10:09 kricsleo

@kricsleo Does not work unfortunately 😢

I will try to provide a minimal reproduction later.

Gwynerva avatar Sep 18 '25 15:09 Gwynerva