0

I'm using an Electron boilerplate, from here: https://github.com/szwacz/electron-boilerplate/

It's using gulp-rollup to bundle the assets, and a dev server can be run with npm start.

Here are my import statements from app.js:

import os from 'os';
import { remote } from 'electron';
import jetpack from 'fs-jetpack';
import env from './env';

import jquery from 'jquery';
import parsley from 'parsleyjs';
import select2 from 'select2/dist/js/select2.js';

import { setupForm } from './form/form';

Everything works fine on an initial load with npm start, but as soon as I edit a file and save, which triggers the watch to reload the build, I get an error:

Error: Could not load select2/dist/js/select2.js (imported by /##/repo-name-example/src/app.js): ENOENT: no such file or directory, open 'select2/dist/js/select2.js'
at /##/repo-name-example/node_modules/rollup/dist/rollup.js:9428:10
at process._tickDomainCallback (internal/process/next_tick.js:129:7)

If I cancel the process and just npm start again, everything is fine.

Why would it forget where select2 is?

1 Answers1

0

Since you are importing this manually using a file path, rather than a named import like the jquery line, you need to use

import select2 from './select2/dist/js/select2.js';

Note the ./ at the beginning. Otherwise, it effectively looks for a module called select2/dist/js/select2.js, rather than using the path.

You also might need to do change it to

import select2 from './node_modules/select2/dist/js/select2.js';

(Assuming thats where the folder is)

SteveEdson
  • 2,485
  • 2
  • 28
  • 46
  • Thanks for spotting that, I tried: `import select2 from '../node_modules/select2/dist/js/select2.js';` But it's now saying: `Error: 'default' is not exported by node_modules/select2/dist/js/select2.js` So I guess maybe it's select2's problem, and their AMD version doesn't seem to be included in this build. – Robert Tolton Jan 14 '17 at 12:40