slimerjs Can not resolve required module, works wi

2019-03-20 21:31发布

问题:

I am trying to create a testing script so that the testers can capture some tests using standalone slimerjs 0.9.3. However when I try to require a local package that I installed(minimist in this case) via npm I get an error.

File structure:

clibrowsers/
    /osx/slimer/slimerjs
    /scripts
        /batchprinter.js
        /node_modules/minimist/
    ...

When I run "clibrowsers/osx/slimer/slimerjs clibrowsers/scripts/batchprinter.js" I get the error:

Script Error: Module: Can not resolve "minimist" module required by main located at file:///Users/USER/Documents/dev/clibrowsers/scripts/batchprinter.js
       Stack:
         -> file:///Users/USER/Documents/dev/clibrowsers/scripts/batchprinter.js: 351

When run the script with with phantomjs 2.0.0 (development) I do not get any errors.

What am I doing wrong?

回答1:

slimer cannot find the node_modules on its own, but you can load the module manually, for instance: var uuid = require(fs.workingDirectory+'/node_modules/node-uuid/uuid.js');

see the doc on slimerjs require