-
Notifications
You must be signed in to change notification settings - Fork 864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
commonjs require on windows #53
Comments
As far as I can see this shows two different problems with Rhino's CommonJS module loader:
|
Hi, thank you for checking this issue. I feel it important for node.js compatibility for at least importing pure JS module. As far as I can see , the mentioned https://github.com/micmath/Rhino-Require was complete (except the C: D: windows error I changed for myself). Rhino.Require details checks all ways to load commonjs that you might also have in ringo.js. |
The Windows paths bug is also reported at #10 |
Hi,
rhino-1.7R4.
I'm experiencing difficulties to load commonjs modules on windows (win 7, powershell env). Please, precise how to properly load commonjs modules if behaviour is not fully standard. I'm just testing with underscore for using a popular module.
Thanks,
ex:
PS D:\temp>mkdir test
PS D:\temp>cd test
PS D:\temp>mkdir node_modules
PS D:\temp>npm install underscore
PS D:\temp\test> java org.mozilla.javascript.tools.shell.Main -require -modules ./node_modules
Rhino 1.7 release 4 2012 06 18
js> require("underscore")
js: "file:/D:/temp/test/node_modules/underscore", line 1: erreur de syntaxe
js: .npmignore
js: .^
js: "file:/D:/temp/test/node_modules/underscore", line 1: La compilation a produit 1 erreur(s) de syntaxe.
removing .npmignore
PS D:\temp\test> rm \node_modules\underscore.npmignore
PS D:\temp\test\node_modules> java org.mozilla.javascript.tools.shell.Main -require -modules ./node_modules
js> require("underscore")
js: uncaught JavaScript runtime exception: ReferenceError: "CNAME" is not defined
removing all folders
PS D:\temp\test\node_modules> java org.mozilla.javascript.tools.shell.Main -require -modules ./node_modules
js> require("underscore")
js: uncaught JavaScript runtime exception: ReferenceError: "favicon" is not defined
PS D:\temp\test\node_modules> ls .\underscore
package.json
README.md
underscore-min.js
underscore.js
PS D:\temp\test\node_modules> java org.mozilla.javascript.tools.shell.Main -require -modules ./node_modules
js> require("underscore")
js: uncaught JavaScript runtime exception: ReferenceError: "README" is not defined
PS D:\temp\test\node_modules> java org.mozilla.javascript.tools.shell.Main -require -modules ./node_modules
js> require("underscore")
js: uncaught JavaScript runtime exception: ReferenceError: "underscore" is not defined
js> require("underscore.js")
js: exception from uncaught JavaScript throw: Error: Module "underscore.js" not found.
in fact cannot load it!
Also, couldn't modules full Path be prefixed with "/" automatically on windows?
PS D:\temp> java org.mozilla.javascript.tools.shell.Main -require -modules /D:/Javascript/Code
Rhino 1.7 release 4 2012 06 18
js> require("time")
[object Object]
js> quit()
PS D:\temp> java org.mozilla.javascript.tools.shell.Main -require -modules D:/path/to/modules
Rhino 1.7 release 4 2012 06 18
js> require("aModule")
org.mozilla.javascript.WrappedException: Wrapped java.net.MalformedURLException: unknown protocol: d
at org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:1754)
at org.mozilla.javascript.commonjs.module.Require.getModule(Require.java:375)
at org.mozilla.javascript.commonjs.module.Require.getExportedModuleInterface(Require.java:264)
at org.mozilla.javascript.commonjs.module.Require.call(Require.java:218)
at org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:63)
at org.mozilla.javascript.gen._stdin__1._c_script_0(Unknown Source)
at org.mozilla.javascript.gen._stdin__1.call(Unknown Source)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:394)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3091)
at org.mozilla.javascript.gen._stdin__1.call(Unknown Source)
at org.mozilla.javascript.gen._stdin__1.exec(Unknown Source)
at org.mozilla.javascript.tools.shell.Main.processSource(Main.java:502)
at org.mozilla.javascript.tools.shell.Main.processFiles(Main.java:178)
at org.mozilla.javascript.tools.shell.Main$IProxy.run(Main.java:102)
at org.mozilla.javascript.Context.call(Context.java:489)
at org.mozilla.javascript.ContextFactory.call(ContextFactory.java:504)
at org.mozilla.javascript.tools.shell.Main.exec(Main.java:160)
at org.mozilla.javascript.tools.shell.Main.main(Main.java:138)
Caused by: java.net.MalformedURLException: unknown protocol: d
at java.net.URL.(URL.java:590)
at java.net.URL.(URL.java:480)
at java.net.URL.(URL.java:429)
at java.net.URI.toURL(URI.java:1096)
at org.mozilla.javascript.commonjs.module.provider.UrlModuleSourceProvider.loadFromActualUri(UrlModuleSourceProvider.java:137)
at org.mozilla.javascript.commonjs.module.provider.UrlModuleSourceProvider.loadFromUri(UrlModuleSourceProvider.java:127)
at org.mozilla.javascript.commonjs.module.provider.UrlModuleSourceProvider.loadFromPathList(UrlModuleSourceProvider.java:112)
at org.mozilla.javascript.commonjs.module.provider.UrlModuleSourceProvider.loadFromPrivilegedLocations(UrlModuleSourceProvider.java:93)
at org.mozilla.javascript.commonjs.module.provider.ModuleSourceProviderBase.loadSource(ModuleSourceProviderBase.java:41)
at org.mozilla.javascript.commonjs.module.provider.CachingModuleScriptProviderBase.getModuleScript(CachingModuleScriptProviderBase.java:69)
at org.mozilla.javascript.commonjs.module.provider.SoftCachingModuleScriptProvider.getModuleScript(SoftCachingModuleScriptProvider.java:67)
at org.mozilla.javascript.commonjs.module.Require.getModule(Require.java:363)
... 16 more
The text was updated successfully, but these errors were encountered: