question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing exports in project dependencies

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
resir014commented, Dec 18, 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.

0reactions
roswell67commented, Apr 24, 2019

Still confused on how people got the “Profiler” object without any import after naming the export… any help here? even the doc isn’t clear.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Content dependencies lost on export and importing again if ...
Content dependencies lost on export and importing again if the content entities do not exist. Needs work. Project: Drupal core. Version:.
Read more >
Project missing dependencies when exported to MSP German
Project dependencies not showing on projects exported to Microsoft Project (MSP). MSP new driver is used and MSP installed in German ...
Read more >
Missing .lib files from exported Visual Studio template
Create a Dependencies folder under the project directory, put the required dlls and libs. Set Proeperties->C/C++->General->Additional Include ...
Read more >
Package dependencies and exports - Jahia Academy
MF file, with the Import-Package and Export-Package headers. If an import or export is missing, or if versions of packages don't match, no ......
Read more >
Job dependencies were lost after importing projects
Export project metadata to csv · Tree view not working after importing a project · Error in new or old jobs on imported...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found