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

Enable building with webpack #209

Closed

Conversation

cowboyd
Copy link

@cowboyd cowboyd commented Jul 20, 2017

When building with WebPack, require('x') returns the module, not the default export, so this just peels off the default export from the module, if it's present.

fixes #207

When building with WebPack, `require('x') returns the module, not the
default export, so this just peels off the default export from the
module, if it's present.
@cowboyd cowboyd force-pushed the allow-building-with-webpack branch from 2acdea4 to 9ffecb8 Compare July 20, 2017 20:50
@ohcibi
Copy link
Contributor

ohcibi commented Aug 28, 2017

@cowboyd I used this commit in an angular-cli project. The problem is that the self executing is somehow executed twice. In the first call the RouteRecognizer or FakeXMLHttpRequest do not even resolve (i.e. they are undefined) leading to another error about .default not being readable from undefined.

@cowboyd
Copy link
Author

cowboyd commented Aug 28, 2017

@ohcibi I assume it doesn't work without this commit either? Can you get it working by checking if RouteRecognizer is defined yet?

@ohcibi
Copy link
Contributor

ohcibi commented Aug 29, 2017

@cowboyd yep, thats exactly the quickfix I have added. You can see the debugger hitting that line twice but at the second time RouteRecognizer is not undefined and your fix comes to action.

I have added that into my real world project to see if it works there that way. The interesting part is that I did not had any error like that there. I was doing it very late yesterday, so I need to investigate a bit more what was happening there (cant do it right now). But I have a clue: In the test project I messed around with the scripts property in the .angular-cli.json by putting the path to pretender into it and found out that this is not necessary when you import that thing directly (i'm still an angular noob). Its very likely that I did not have anything in my scripts in the real world project and that this error doesn't happen when one imports pretender normally via an import statement. The more I write this the more convinced I am that this is the problem. Will test it asap.

@ohcibi
Copy link
Contributor

ohcibi commented Aug 29, 2017

Yep. Nevermind. The fix works as intended and I was misusing angular-cli.

@cowboyd
Copy link
Author

cowboyd commented Aug 29, 2017

@trek @stefanpenner Any thoughts on what it will take for this to be kosher to merge? We've been using this patch for over a month without problems, but that's just one data point. I'm not sure if there's a good way to test this, short of setting up a webpack build for it.

Also, it looks like this isn't the only effort to make module lookup work in different environments, so piling on another hack might not be the right answer. Then again...

@cowboyd
Copy link
Author

cowboyd commented Nov 8, 2017

Made redundant by #216 🎉

@cowboyd cowboyd closed this Nov 8, 2017
@cowboyd cowboyd mentioned this pull request Feb 2, 2018
1 task
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

Successfully merging this pull request may close these issues.

When importing Pretender from a webpack build, RouteRecognizer constructor lookup fails.
2 participants