0

I'm building my library using Rollup.js. After bundling, I want to run it via node command like:

node -e "require('./dist/index.min.js')"

But it throws me an error:

internal/modules/cjs/loader.js:605
    throw err;
    ^

Error: Cannot find module './polyfills.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:603:15)
    at Function.Module._load (internal/modules/cjs/loader.js:529:25)
    at Module.require (internal/modules/cjs/loader.js:659:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at XYZ/dist/index.min.js:583:17
    at Object.<anonymous> (XYZ/dist/index.min.js:9767:21)
    at Module._compile (internal/modules/cjs/loader.js:723:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:734:10)
    at Module.load (internal/modules/cjs/loader.js:620:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:560:12)

Side info: The build command run just fine and create output file in dist folder as intended.

My rollup config:

import babel from 'rollup-plugin-babel'
import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import uglify from 'rollup-plugin-uglify-es'
import json from '@rollup/plugin-json'
import builtins from 'rollup-plugin-node-builtins'
import globals from 'rollup-plugin-node-globals'

export default {
  input: 'src/index.js',
  plugins: [
    globals(),
    builtins(),
    babel({
      exclude: 'node_modules/**'
    }),
    resolve(),
    commonjs(),
    json(),
    uglify()
  ],
  output: {
    extend: true,
    compact: true,
    file: 'dist/index.min.js',
    format: 'iife',
    name: 'lib',
    sourcemap: 'dist/index.js.map'
  },
};

My .babelrc file:

{
  "presets": [
    "@babel/env"
  ]
}

I've tried to install @babel/polyfill and import it in the src/index.js file, but it that didn't fix the error.

lukaszkups
  • 5,790
  • 9
  • 47
  • 85
  • Was this ever fixed? I have the same issue where a module cannot be found. – binarydreams Aug 14 '20 at 11:30
  • I've never found a solution for this and I've abandoned approach that uses Rollup as a bundler for this particular project. – lukaszkups Aug 14 '20 at 11:32
  • thank for replying so promptly. Can I ask what are you using to bundle now? I use Nexe to use that bundled.js file so I can run the exe on windows – binarydreams Aug 14 '20 at 11:48
  • I've created Vue.js project, generated via Vue-CLI that's running inside [NW.js](https://nwjs.io/) wrapper (so I can run it as desktop app as well) – lukaszkups Aug 14 '20 at 12:26

0 Answers0