Skip to content
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

In Browserify: "Cannot find module './aes'" #294

Closed
ptarjan opened this issue Sep 4, 2015 · 4 comments
Closed

In Browserify: "Cannot find module './aes'" #294

ptarjan opened this issue Sep 4, 2015 · 4 comments
Milestone

Comments

@ptarjan
Copy link

ptarjan commented Sep 4, 2015

When packaging your library into a browserify project, I get

"Cannot find module './aes'"

For a module to work in browserify, its require()s need to be statically analyzable. I'm not sure the easiest way to do that for you, but just putting

require('./aes');
require('...')

would probably do the trick. I know it is duplicative, so maybe you can find a way that isn't duplicating code but yet is still statically analyzable.

One way to test would probably be this:

$ browserify ./js/forge.js | node
module.js:338
    throw err;
          ^
Error: Cannot find module './aes'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at s ([stdin]:1:114)
    at [stdin]:1:305
    at [stdin]:32:14
    at Array.map (native)
    at Object.module.exports ([stdin]:31:21)
    at defineFunc ([stdin]:48:10)

And make it so that it doesn't throw anymore.

image

@dlongley
Copy link
Member

dlongley commented Sep 5, 2015

Revamping the module system is on the roadmap -- we jotted down some preliminary ideas here: #126.

In general, we need to get a tool chain setup that can wrap forge modules in a variety of different ways for different loaders (AMD/CommonJS/browserify/etc). Just haven't had the time to get to it yet; PRs welcome!

But, we could potentially look into the kind of change you're talking about as a near term fix for browserify should some time shake loose. We need to ensure that any change doesn't cause havoc with the other ways people are loading the library, which means better module loader tests are needed as well.

@fujifish
Copy link

fujifish commented Jun 29, 2016

for what it's worth, I was able to workaround this by generating and using the standalone forge bundle and then replacing every occurrence of require('node-forge') with window.forge.

In package.json:

"dependencies": {
  "node-forge": "0.6.40"
},
"main": "main.js",
"scripts": {
  "forge": "(cd node_modules/node-forge && npm install && npm run bundle && cp js/forge.bundle.js ../../)",
  "build": "npm run forge && browserify main.js | sed \"s/require[(]'node-forge'[)]/window.forge/g\" > bundle.js"
}

Then in the HTML:

<head>
  <script src="forge.bundle.js"></script>
  <script src="bundle.js"></script>
</head>

@dlongley
Copy link
Member

Should hopefully be solved by #357 (comment).

@dlongley
Copy link
Member

Should be addressed in a new release now that #456 has been merged.

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

No branches or pull requests

4 participants