screeps-typescript-starter icon indicating copy to clipboard operation
screeps-typescript-starter copied to clipboard

CJS modules with default exports do not work

Open linker-err0r opened this issue 6 years ago • 1 comments

I've tried a few of them, and so far, this class of modules seems to fail when it should be able to run in Screeps.

Consider this code added to main.ts in starter:

 // already in es6, of course
import { ErrorMapper } from "utils/ErrorMapper";

// this one works -- it's in es6 format
import * as _ from 'lodash-es'; 

 // uploads, but exports empty object
import * as _ from 'lodash';

// no error and these will upload, but code will fail on server without executing
import * as Chance from 'chance';
import * as faker from 'faker'; 

Please note that I have also taken the step of installing @types modules for these as well.

linker-err0r avatar Jul 30 '18 01:07 linker-err0r

Using CommonJS modules w/ Rollup will have to require some workarounds.

See: https://screepers.gitbook.io/screeps-typescript-starter/in-depth/module-bundling#note-rollup-and-named-exports

resir014 avatar Aug 01 '18 04:08 resir014