Skip to content
This repository has been archived by the owner on Oct 9, 2020. It is now read-only.

Facing a hard time of "require" a node module in an experimental plugin #409

Closed
jack4it opened this issue Nov 23, 2015 · 3 comments
Closed

Comments

@jack4it
Copy link

jack4it commented Nov 23, 2015

I'm trying to write a systemjs plugin, but facing a hard time of "require" a npm module. The require always tries to resolve the node module from right at the root of the app, instead of node_modules folder. Why? How systemjs builder resolve the plugins and teach the plugins to load subsequent node modules?

It fails even this is the only line in my plugin.js. I have installed less both via jspm install npm:less and npm install less. By the way, is it possible to pass --no-optional through jspm install to npm install? The dependencies pulled in via jspm install npm:less is a little crazy... :(

var lessc = require("less");
E:\__prj\systemjs-test>node build.js
Build error
[Error: ENOENT: no such file or directory, open 'E:\__prj\systemjs-test\asap.js']

Thanks!

@jack4it
Copy link
Author

jack4it commented Nov 24, 2015

Succeeded with :) Maybe should somehow document this as, at least a Tip

System._nodeRequire("less")

@jack4it
Copy link
Author

jack4it commented Nov 24, 2015

I just realized, it is not just _nodeRequire is required to use here, but also the respective node module has to be installed by npm install...

Why can't systemjs load the modules installed by jspm install when executing in node? Now we have to duplicate the npm packages, if we have to use the package in both browser and node? :(

@jack4it jack4it reopened this Nov 24, 2015
@guybedford
Copy link
Member

@jack4it see https://github.com/jspm/jspm-cli/blob/master/docs/nodejs-usage.md for more info. Full server-side execution support is coming in jspm 0.17.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants