nitrojs / nitrojs/nitro

Issue with bundling `css-tree`

Open
#3,582 1 comment 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

nitropack: 2.12.6
node: 20.19.1

Reproduction

https://stackblitz.com/edit/github-zcdft7zb?file=package.json,server%2Froutes%2Findex.ts

Describe the bug

In dev mode the reproduction will work just fine. The event handler will return the JSON imported from a package.
After building and starting the app, the same event handler will throw an error:

cause: Error: Cannot find module '../data/patch.json'
Additional context

This happens because of this import in the event handler:

import data from 'css-tree/definition-syntax-data-patch'

Which looks like this:

import { createRequire } from 'module';

const require = createRequire(import.meta.url);
const patch = require('../data/patch.json');

export default patch;

It's requiring a file called patch.json, which is missing from the output:

~/projects/jvmipzvolv.github/.output/server/node_modules/css-tree
❯ ls -la
total 4
drwxrwxr-x  1  staff  staff     2  Sept  22  13:43  ./             
drwxrwxr-x  1  staff  staff     1  Sept  22  13:43  ../            
drwxrwxr-x  1  staff  staff     1  Sept  22  13:43  lib/           
-rw-r--r--  1  staff  staff  3883  Sept  22  13:43  package.json 
Logs

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 with the StackBlitz reproduction, package.json, and server/routes/index.ts, then inspect how the built output under .output/server/node_modules/css-tree is produced. Reproduce the difference between dev and build/start with the css-tree/definition-syntax-data-patch import. Done means the built app can load the imported JSON without the missing-module error.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.