nitro icon indicating copy to clipboard operation
nitro copied to clipboard

Support bundling `.node` modules

Open cyperdark opened this issue 2 years ago • 4 comments

Environment

Nodejs: 16.20.0 Nitropack: 2.5.2 rosu-pp: 0.9.4

Reproduction

  1. npx giget@latest nitro oops
  2. npm i rosu-pp
  3. import module somewhere in project
  4. npm run dev

Describe the bug

image

Look like this import cause this issue: image

source code

Additional context

No response

Logs

No response

cyperdark avatar Jul 09 '23 02:07 cyperdark

Hello, any updates on this one? maybe there a work around

cyperdark avatar Sep 07 '23 13:09 cyperdark

@pi0 Hello, it's been over a 7 months, any news regarding this one?

cyperdark avatar May 17 '24 00:05 cyperdark

Hi dear @cyperdark. Bundling .node dependencies is not supported yet. You are welcome to contribute and add support (it should be via rollup plugins)

pi0 avatar May 17 '24 07:05 pi0

sorry, i can't contribute, repo is difficult to understand for me. And i got issues running it locally, even tho i did all steps from here: https://github.com/unjs/nitro?tab=readme-ov-file#contribution

found a way to bundle the package by adding this plugin i found in internet

import path from 'path';


export default defineNitroConfig({
  rollupConfig: {
    plugins: [
      {
        name: '.node',
        resolveId(source: string) {
          return source.endsWith('.node') ? path.resolve(source) : null;
        },
        load(id: string) {
          return id.endsWith('.node') ? `module.exports = require(${JSON.stringify(id)});` : null;
        },
      }
    ],
  },
});

cyperdark avatar Oct 11 '24 05:10 cyperdark