I am attempting to bundle my Node.js TypeScript backend application code and dependencies (node_modules) into a single JavaScript file named “bundle.js”.
I got this error when i ran npm run build
where build : rollup -c
Error: [!] (plugin rpt2) Error: Unexpected character ‘�’ (Note that you need plugins to import files that are not JavaScript)node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-darwin-x64-93.node (1:0)
This is my rollup.config.js file:
import nodeBuiltins from 'rollup-plugin-node-builtins';
import commonjs from 'rollup-plugin-commonjs';
import resolve from 'rollup-plugin-node-resolve';
import typescript from 'rollup-plugin-typescript2';
import tslibResolveId from 'rollup-plugin-tslib-resolve-id';
import json from '@rollup/plugin-json';
export default {
input: 'src/server.ts',
output: {
file: 'dist/bundle.js',
format: 'cjs',
},
plugins: [
tslibResolveId(),
nodeBuiltins(),
typescript(),
json(),
commonjs({
include: 'node_modules/**',
ignoreGlobal: false,
sourceMap: false,
}),
resolve(),
],
};
You’d need something like github.com/danielgindi/rollup-plugin-natives to deal with the non-JS files.
@jonrsharpe Am I able to execute the bundle.js without the node_modules?