New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing exports in project dependencies #77

Closed
Hopobcn opened this Issue Dec 16, 2017 · 4 comments

Comments

Projects
None yet
3 participants
@Hopobcn

Hopobcn commented Dec 16, 2017

I've found an issue (and a possible solution) when loading screps-profiler to a project. I add this issue in case it's useful for others.

Use case:

function ploop() {
  if (Config.USE_PROFILER) {
    Profiler.wrap(mloop);
  } else {
    mloop();
  }
}
export const loop = ErrorMapper.wrapLoop(ploop);

Expected behaviour:

  • Uploaded dist/main.js contains a bundled screeps-profiler

Actual behaviour:

$ yarn push-develop
yarn run v1.3.2
$ rollup -c --dest develop

src/main.ts → dist/main.js...
(!) Missing exports
https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module
src/main.ts
enable is not exported by node_modules/screeps-profiler/screeps-profiler.js
5: // Screeps system reloads your script.
6: if (Config.USE_PROFILER) {
7:     Profiler.enable();
                ^
8: }
9: /*
src/main.ts
wrap is not exported by node_modules/screeps-profiler/screeps-profiler.js
29: function ploop() {
30:     if (Config.USE_PROFILER) {
31:         Profiler.wrap(mloop);
                     ^
32:     }
33:     else {

And dist/main.js has some undefined calls:

function ploop() {
    if (USE_PROFILER) {
        undefined(mloop);
    }
    else {
        mloop();
    }
}

In game console:

[10:07:40]TypeError: undefined is not a function
    at main:2356:5
    at eval:2398:4
    at Object.<anonymous>:2:143116
    at Object.r.runCode:2:143673

Possible Solution:

In rollup.config.js, add a namedExprots section to commonjs plugin to manually export enable and wrap functions.

commonjs({
      namedExports: {
        'node_modules/screeps-profiler/screeps-profiler.js': ['enable', 'wrap']
      }
    }),

Maybe screeps-typescript-starter/docs/in-depth/module-bundling.md could be modified to specify the rollup.config.js modifications required.

Does anyone have a better solution than this?

@resir014

This comment has been minimized.

Member

resir014 commented Dec 17, 2017

Good catch! I'll go ahead and update those docs now.

@resir014

This comment has been minimized.

Member

resir014 commented Dec 17, 2017

@Hopobcn and to answer your question, unfortunately no. Rollup has first-class support for bundling ES6 modules, but screeps-profiler is a CommonJS module, which means the module along with its named exports need to be resolved using rollup-plugin-commonjs.

Webpack gets around this by making everything a CommonJS module and then reimplementing the CommonJS require() system client-side, which gets around the namedExports issue at the expense of larger bundle size (which explains the seemingly boilerplate code it generates).

I could be wrong though, @apemanzilla can probably correct me.

@dmarcuse

This comment has been minimized.

Contributor

dmarcuse commented Dec 17, 2017

Yeah, this is an issue with the way screeps-profiler is written and a limitation of rollup unfortunately.

@resir014

This comment has been minimized.

Member

resir014 commented Dec 21, 2017

Anyways, the docs have been updated. This can be closed now.

@resir014 resir014 closed this Dec 21, 2017

@resir014 resir014 added the docs label Dec 21, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment