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

browserify #113

Closed
boneskull opened this issue May 11, 2020 · 11 comments
Closed

browserify #113

boneskull opened this issue May 11, 2020 · 11 comments

Comments

@boneskull
Copy link
Contributor

there's some stuff in the works to move Mocha way from browserify and onto webpack, but not sure when that'll land.

in the meantime, I'm struggling to get rewiremock working in a browserify bundle via karma. it's throwing an exception because require.resolve does not exist. first, it throws because of the node-libs-browser module:

  Uncaught TypeError: require.resolve is not a function
  at /var/folders/74/theKashey/rewiremock/node_modules/node-libs-browser/index.js:1:1 <- /var/folders/74/p0gxrmy93fq88nm66cs7z42h0000gn/T/55824eb469904ee97753db535d0bc15b.browserify.js:46563:31

Even if that's addressed somehow, it will certainly throw in the two other places that use require.resolve in the codebase (nested.js & mockModule.js).

For this to work, I'm going to guess you'd want to publish a browser bundle and reference it in the browser field of package.json--or otherwise point to a non-bundled, browser-specific implementation. But that's just my guess.

But... this may be a "WONTFIX" for you--and I get it. Just something I ran into and thought it wouldn't hurt to mention.

@boneskull
Copy link
Contributor Author

(Browserify itself will replace references to require.resolve with its own resolve module, but it is nontrivial to try to create a browserify bundle for a dependency)

@theKashey
Copy link
Owner

  • node-libs-browser is used only for webpack (however should be used for mocha case as well), but as long as all the stuff imported statically - it's causing issues for mocha. I am not sure which approach is better here.

  • require.resolve is not a problem. It's better to call them "leftovers" - in both cases it's used to self-wipe - delete require.cache[require.resolve(__filename)];, and there is a better function for it.

@theKashey
Copy link
Owner

@boneskull - please try that branch.

@boneskull
Copy link
Contributor Author

boneskull commented May 19, 2020

I get

Uncaught Error: Rewiremock: there is no "parent module". Is there two HotModuleReplacementPlugins?

This happens when my test file does require('rewiremock/node') or require('rewiremock')

@boneskull
Copy link
Contributor Author

It'd also (theoretically) work if there was a "globals" bundle of rewiremock available. Then I could make it work in Karma by throwing it in a <script> tag, and browserify wouldn't need to know about it.

@boneskull
Copy link
Contributor Author

(That branch works when running in node, just not in karma/karma-browserify)

@theKashey
Copy link
Owner

theKashey commented May 19, 2020

Uncaught Error: Rewiremock: there is no "parent module"

Sounds like a problem with browserify module system, if it even exists.

So:

Gonna double check how browserify works today...

@theKashey
Copy link
Owner

Look like there is no implementation of a real module system, as long as it's not really needed in "runtime".
Is it possible for you not to use browserify, but use webpack? 99% of the functionality works there.

@theKashey theKashey reopened this May 20, 2020
@boneskull
Copy link
Contributor Author

K, thanks for looking in to this. I think Mocha is moving to webpack anyway. not sure if you meant to leave this open.

@boneskull
Copy link
Contributor Author

I was wrong; we're not going to use webpack--looks like we're going to use rollup instead. This doesn't mean we're going to adopt ESM modules, though, given the current set of challenges there.

@theKashey
Copy link
Owner

rollup's module system is a unknown for me yet. Haven't tried it, but reckon it should not be a problem.

However it should not work out of the box.

Probably it's time to close this issue with WONT FIX, and open a new one for rollup.

@theKashey theKashey mentioned this issue May 21, 2020
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

2 participants