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

dynamic imports fix for non-webpack environments. #3414

Merged
merged 3 commits into from
Dec 8, 2017

Conversation

PrudviGali
Copy link
Contributor

@PrudviGali PrudviGali commented Dec 7, 2017

Added issue description in #3345 .

Feature detection condition comes handy rather than typeof window because of webpack specific methods require.resolveWeak and resolve.ensure fails in non-webpack environments.

The issue was not with window object but with require.resolveWeak and require.ensure methods used in next handle-import.js file. Both these methods are specific to webpack and would not be available in node/commonjs environment. Jest runs in Node environment and does not recognize require.resolveWeak and require.ensure methods.

TC39 dynamic import proposal works pretty well with Jest testing. Please refer to the repo. But Nextjs implementation of dynamic imports fails in jest because of above two methods repo.

@arunoda already mentioned that should not use process.env.NODE_ENV === 'test' in #3405. Assuming this would be the appropriate way of handling this issue #3345 .

@PrudviGali PrudviGali changed the title dynamic imports fix for non webpack environments. dynamic imports fix for non-webpack environments. Dec 7, 2017
@PrudviGali PrudviGali mentioned this pull request Dec 7, 2017
1 task
@arunoda
Copy link
Contributor

arunoda commented Dec 7, 2017

Oh! I didn't see this: #3414
(Was thinking this is something else)

Sorry for that.
Looks interesting.

@@ -9,7 +9,7 @@ const TYPE_IMPORT = 'Import'

const buildImport = (args) => (template(`
(
typeof window === 'undefined' ?
typeof require.resolveWeak !== 'function' ?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment where why we use this rather a simple window check.
It's better for someone who's reading the code.

Copy link
Contributor

@arunoda arunoda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the status.

@PrudviGali
Copy link
Contributor Author

@arunoda No problem. I should have added documentation in the first place.

Anyhow added the requested changes.

Copy link
Contributor Author

@PrudviGali PrudviGali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added requested changes

@arunoda
Copy link
Contributor

arunoda commented Dec 8, 2017

@PrudviGali this looks great.
Thanks.

@arunoda arunoda merged commit bd20deb into vercel:canary Dec 8, 2017
@PrudviGali
Copy link
Contributor Author

@arunoda Cool. Thanks.

@timneutkens
Copy link
Member

Very nice, thanks @PrudviGali!

@lock lock bot locked as resolved and limited conversation to collaborators May 16, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants