reactiverse / es4x

🚀 fast JavaScript 4 Eclipse Vert.x
https://reactiverse.io/es4x/
Apache License 2.0
877 stars 75 forks source link

Require statements fail to resolve json files from dependency except by relative path #580

Closed chefhoobajoob closed 2 years ago

chefhoobajoob commented 2 years ago

Given a filesystem layout like this:

/lib
  |
  --> main.js
/node_modules
  |
  -->some-dependency
       |
       -->some-directory
             |
             -->some-file.json

A require statement like this in lib/main.js:

const someJson = require('some-dependency/some-directory/some-file.json')

...will generate a module load exception like this on es4x 0.17.0:

ModuleError: Module "some-dependency/some-directory/some-file.json" was not found
        at <js> Require.resolve(node_modules\.lib\es4x-0.17.0.jar!\io\reactiverse\es4x\jvm-npm.js:122:3628-3706)
        at <js> Require(node_modules\.lib\es4x-0.17.0.jar!\io\reactiverse\es4x\jvm-npm.js:89:2669-2695)
        at <js> this.require(node_modules\.lib\es4x-0.17.0.jar!\io\reactiverse\es4x\jvm-npm.js:46:1459-1475)

In order to successfully use require for json files on es4x 0.17.0, a relative path (from the directory where the js file with the require statement is included) is required, like so:

const someJson = require('../node_modules/some-dependency/some-directory/some-file.json')

The require statement should not require relative path specifications for json files provided by dependencies.