Skip to content

Conversation

@chaensel
Copy link

these modifications allow module loading from jar files

I modified the resolve logic so that modules located within jar files (or somewhere else within the classpath) can be loaded.
I replaced the ECMAScript 6 function 'startsWith' with 'indexOf' to support a wider range of engines.
@lance
Copy link
Contributor

lance commented Mar 3, 2016

Your changes to resolveAsDirectory and resolveAsFile are unnecessary. The first thing that Require.resolve checks is resolveCoreModule here https://github.com/nodyn/jvm-npm/blob/master/src/main/javascript/jvm-npm.js#L117.

There is, in fact, already a very basic test for loading from the classpath here: https://github.com/nodyn/jvm-npm/blob/master/src/test/javascript/specs/requireSpec.js#L264-L267. I think the root of the issue you are experiencing, and the reason your change may work in your environment is related to the normalizeName function. Can you please provide a test case showing the expected behavior?

@Frankst2
Copy link

Just FYI: I also had the problem that loading a module via "normal" execution directly in my project worked fine, but then in the jar it didn't work. It turned out that I actually used the wrong(?) module name in the require(...) function call (I accidentally had the same module two times in my project: node_modules/automapper-ts/dist/automapper.js and src/main/resources/automapper.js). require('automapper-ts') then only worked directly when executing in the source folder, with require('automapper') (so the file name) it worked fine in both cases.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants