Missing exports in project dependencies
See original GitHub issueI’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:
-
We add screeps-profiler dependency as stated in screeps-typescript-starter/docs/in-depth/module-bundling.md:
npm install screeps-profiler
-
Then we modify
src/main.js
to insert all required code:
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:
- Created 6 years ago
- Comments:5 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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 thenamedExports
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.
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.