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.

Map directories/files to node_modules

See original GitHub issue

Expected Behavior

Normally we have dependencies (like js-yaml, c3js,…) installed in node_modules. It should be possible to define kind of mapping:

"my/library/thirdparty/ext.min.js": "node_modules/ext/dist/ext.min.js"

This mapping setting should be used in “ui5 serve” & “ui5 build”.

Current Behavior

It’s only possible to define mapping to the src, test and webapp directories.

Steps to reproduce the issue

Context

Affected components (if known)

Log Output / Stack Trace

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:4
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
sven-petersencommented, Apr 9, 2019

+1 on this feature. I want to use highcharts in a library. Unfortunately they have a different folder structure (which you can see here) where the main library file is on root level. So there mapping has to point to ./. However this brakes the build as the builder also processes all subfolders and the ./es-modules-folder contains .js files that cannot be processed (see and example error below). And all I need is actually just a single js-file from the highcharts library. So even if the processing of the files wouldn’t fail I don’t want it to include them in the build.

ERR! lbt:resources:ResourcePool    'Error: Line 335: Unexpected token\n
    at ErrorHandler.constructError ([...]/ui/node_modules/esprima/dist/esprima.js:5012:22)\n
    at ErrorHandler.createError ([...]/ui/node_modules/esprima/dist/esprima.js:5028:27)\n
    at Parser.unexpectedTokenError ([...]/ui/node_modules/esprima/dist/esprima.js:1985:39)\n
    at Parser.tolerateUnexpectedToken ([...]/ui/node_modules/esprima/dist/esprima.js:1998:42)\n
    at Parser.parseStatementListItem ([...]/ui/node_modules/esprima/dist/esprima.js:3371:31)\n
    at Parser.parseScript ([...]/ui/node_modules/esprima/dist/esprima.js:4723:29)\n
    at parse ([...]/ui/node_modules/esprima/dist/esprima.js:122:61)\n
    at Object.parseScript ([...]/ui/node_modules/esprima/dist/esprima.js:145:13)\n
    at determineDependencyInfo ([...]/ui/node_modules/@ui5/builder/lib/lbt/resources/ResourcePool.js:77:25)\n
    at process._tickCallback (internal/process/next_tick.js:68:7)' }
ERR! lbt:resources:ResourcePool Error: Line 188: Unexpected token
ERR! lbt:resources:ResourcePool     at ErrorHandler.constructError ([...]/ui/node_modules/esprima/dist/esprima.js:5012:22)
ERR! lbt:resources:ResourcePool     at ErrorHandler.createError ([...]/ui/node_modules/esprima/dist/esprima.js:5028:27)
ERR! lbt:resources:ResourcePool     at Parser.unexpectedTokenError ([...]/ui/node_modules/esprima/dist/esprima.js:1985:39)
ERR! lbt:resources:ResourcePool     at Parser.tolerateUnexpectedToken ([...]/ui/node_modules/esprima/dist/esprima.js:1998:42)
ERR! lbt:resources:ResourcePool     at Parser.parseStatementListItem ([...]/ui/node_modules/esprima/dist/esprima.js:3371:31)
ERR! lbt:resources:ResourcePool     at Parser.parseScript ([...]/ui/node_modules/esprima/dist/esprima.js:4723:29)
ERR! lbt:resources:ResourcePool     at parse ([...]/ui/node_modules/esprima/dist/esprima.js:122:61)
ERR! lbt:resources:ResourcePool     at Object.parseScript ([...]/ui/node_modules/esprima/dist/esprima.js:145:13)
ERR! lbt:resources:ResourcePool     at determineDependencyInfo ([...]/ui/node_modules/@ui5/builder/lib/lbt/resources/ResourcePool.js:77:25)
ERR! lbt:resources:ResourcePool     at process._tickCallback (internal/process/next_tick.js:68:7)
ERR! lbt:resources:ResourcePool  failed to parse or analyze %s: com/sap/de/ui/controls/thirdparty/highcharts/es-modules/parts/Axis.js { Error: Line 188: Unexpected token
ERR! lbt:resources:ResourcePool     at ErrorHandler.constructError ([...]/ui/node_modules/esprima/dist/esprima.js:5012:22)
ERR! lbt:resources:ResourcePool     at ErrorHandler.createError ([...]/ui/node_modules/esprima/dist/esprima.js:5028:27)
ERR! lbt:resources:ResourcePool     at Parser.unexpectedTokenError ([...]/ui/node_modules/esprima/dist/esprima.js:1985:39)
ERR! lbt:resources:ResourcePool     at Parser.tolerateUnexpectedToken ([...]/ui/node_modules/esprima/dist/esprima.js:1998:42)
ERR! lbt:resources:ResourcePool     at Parser.parseStatementListItem ([...]/ui/node_modules/esprima/dist/esprima.js:3371:31)
ERR! lbt:resources:ResourcePool     at Parser.parseScript ([...]/ui/node_modules/esprima/dist/esprima.js:4723:29)
ERR! lbt:resources:ResourcePool     at parse ([...]/ui/node_modules/esprima/dist/esprima.js:122:61)
ERR! lbt:resources:ResourcePool     at Object.parseScript ([...]/ui/node_modules/esprima/dist/esprima.js:145:13)
ERR! lbt:resources:ResourcePool     at determineDependencyInfo ([...]/ui/node_modules/@ui5/builder/lib/lbt/resources/ResourcePool.js:77:25)
ERR! lbt:resources:ResourcePool     at process._tickCallback (internal/process/next_tick.js:68:7)

if someone elese stumbles across this issue and there is no better fix yet: I am using patch-package in order to automatically delete all files except for the ones I need. Not nice but it works. Hope this is not yet another of those permanent “temporary workarounds”.

0reactions
RandomBytecommented, Apr 9, 2019

@aktivalux I guess an exclude configuration as discussed here could already help. However I see that the per-file mapping would be more useful in this case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I make multiple projects share node_modules ...
You absolutely can share a node_modules directory amongst projects. From node's documentation: If the module identifier passed to require() is not a native ......
Read more >
map-folder - npm
Create a JSON representation of a folder structure tree. ... Start using map-folder in your project by running `npm i map-folder`.
Read more >
CommonJS modules | Node.js v19.3.0 Documentation
Core modules; Cycles; File modules; Folders as modules; Loading from node_modules folders; Loading from the ... The Module object; Source map v3 support ......
Read more >
Working with folders in Node.js
The Node.js fs core module provides many handy methods you can use to work with folders. Check if a folder exists. Use fs.access()...
Read more >
The magic behind npm link - Medium
Note: You can specify a NODE_PATH environment variable to make Node.js search for modules in other folders, but it is not recommended. Loading...
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