nitrojs / nitrojs/nitro

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

Open
#3,565 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug v2
Dominant language
TypeScript
Stars
11.2k
Forks
899
Avg merge
2d 24m
Merged PRs (30d)
40

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing Nitro's nitro.externals and rollupConfig.external handling for local monorepo packages. Reproduce the build with the prose and nuxtApp packages, then inspect the generated .output/server and node_modules contents. Done means the package is not inlined, remains available in the deployment output, and preserves the JSX runtime behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
bun, typescript
Domain
backend, build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.