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

upgrade to webpack v5 stable version #602

Merged
merged 10 commits into from
Oct 31, 2020
Merged

upgrade to webpack v5 stable version #602

merged 10 commits into from
Oct 31, 2020

Conversation

huozhi
Copy link
Member

@huozhi huozhi commented Oct 13, 2020

since webpack 5 stable version is released, try to adopt it to ncc

@huozhi huozhi changed the title upgrade to webpack 5 upgrade to webpack v5 stable version Oct 13, 2020
Copy link
Member

@styfle styfle left a comment

Choose a reason for hiding this comment

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

Looks like the watcher API changed causing the test to fail.

Previously, it was changed from expect(missing.length).toBeGreaterThan(100) to expect(missing._set.size).toBeGreaterThan(100) in PR #579 so perhaps you could try changing it back?

@huozhi
Copy link
Member Author

huozhi commented Oct 13, 2020

looks like the previous code doesn't work as well. I logged the missing._set, missing._set is always 43 on my side. do you know why it's expecte to be over 100 and what does this condition mean? @styfle @guybedford

@huozhi
Copy link
Member Author

huozhi commented Oct 13, 2020

webpack 5.0.0-beta.29 includes a fixing "fix watching when more than 2000 directories are watched on MacOS", could this be related to it? sounds like webpack tried to reduce the watchers count, so less than 100 might be expected?

@styfle
Copy link
Member

styfle commented Oct 13, 2020

But the failures are only happening on Linux, macOS passes CI

@huozhi
Copy link
Member Author

huozhi commented Oct 23, 2020

Note added:

sometimes the CI failed with test "Should support custom watch API" that missing._set.size is less than 100 on ubuntu VM. I also encounter this issue sometimes on my macbook laptop with the exact same error message. after I logged the missing._set I found that the file paths inside are not correct. like '/Users/myname/code/ncc/Users/myname/package.json' the Users/myname has been duplicated 2 times.

@styfle
Copy link
Member

styfle commented Oct 23, 2020

I found that the file paths inside are not correct

Sounds like a webpack bug?

@huozhi
Copy link
Member Author

huozhi commented Oct 24, 2020

Founding

I'm doubting it's a issue while webpack working with twilio.js since twilio requires native nodejs module and webpack 5 won't polyfill them. I created a gist to run webpack@5 with custom watch (same with watcher.test.js) to compile twilio.js (same with test/integration/twilio.js) 👉 link

and I got logs below

Module not found: Error: Can't resolve 'util' in '/Users/huozhi/Code/test/webpack5/node_modules/twilio/lib/twiml'                                                                                  [45/4307]

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "util": require.resolve("util/") }'
        - install 'util'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "util": false }
 @ ./node_modules/twilio/lib/index.js 48:46-78
 @ ./twilio.js 1:15-32

ERROR in ./node_modules/twilio/lib/webhooks/webhooks.js 3:13-30
Module not found: Error: Can't resolve 'crypto' in '/Users/huozhi/Code/test/webpack5/node_modules/twilio/lib/webhooks'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
        - install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "crypto": false }
 @ ./node_modules/twilio/lib/index.js 4:15-45
 @ ./twilio.js 1:15-32

currently ncc swallowed these errors that I can't see them even turn the webpack stats.logging flag to "verbose".

in webpack@5.0.0-beta.31 they add this change: add resolve.fallback option and recommend that for polyfilling. I guess that's why it breaks after bumping webpack version higher than beta-28.

Followup

  • does ncc want to support nodejs fallback out of box?
  • or user need to provide fallback aliases like webpack suggested?

@huozhi huozhi requested a review from styfle October 24, 2020 04:38
@styfle
Copy link
Member

styfle commented Oct 24, 2020

Nice find!

I was thinking the Node.js fallback was removed during the webpack beta but I guess we are a bit outdated as you mentioned.

does ncc want to support nodejs fallback out of box?

I think we need to have the Node.js fallback out of the box like the old webpack because ncc is designed specifically for Node.js

@@ -97,7 +97,7 @@ jest.setTimeout(30000);

it('Should support custom watch API', async () => {
let buildCnt = 0;
const buildFile = path.resolve('./test/integration/request.js');
const buildFile = path.resolve('./test/integration/twilio.js');
Copy link
Member

Choose a reason for hiding this comment

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

Does it work work with request now that node-libs-browser is added?

Copy link
Member Author

Choose a reason for hiding this comment

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

request.js will work for both whatever you add the nodejs lib fallback support or not. twilio.js doesn't work without fallback that breaks the watcher test case.

I changed the original file from twilio to request to let it pass the test in last commit.

src/index.js Outdated Show resolved Hide resolved
@huozhi huozhi requested a review from styfle October 25, 2020 12:46
src/index.js Outdated
@@ -205,8 +205,7 @@ module.exports = (
mainFields: ["main"],
plugins: resolvePlugins
},
// https://github.com/vercel/ncc/pull/29#pullrequestreview-177152175
node: false,
node: {},
Copy link
Member

Choose a reason for hiding this comment

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

Is {} different than false?

I'm looking at the docs between v4 and v5 and the false value seems to be the same for both.

https://v4.webpack.js.org/configuration/node/

https://webpack.js.org/configuration/node/

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought it was the root cause to trigger the error but looks like it just accidently passed tests..after rerun the tests they're still failed. reverted

Copy link
Member Author

Choose a reason for hiding this comment

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

wonder why CI gets passed now...seems the nodejs lib fallback wasn't the issue before? I'm still stucking at watcher test failure on my local laptop 🤔 ...

@huozhi huozhi requested a review from styfle October 27, 2020 00:41
@styfle styfle added automerge Automatically merge PR once checks pass hacktoberfest-accepted labels Oct 31, 2020
Copy link
Member

@styfle styfle left a comment

Choose a reason for hiding this comment

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

Looks good now, thanks!

@kodiakhq kodiakhq bot merged commit 8e1e5fc into vercel:master Oct 31, 2020
@huozhi huozhi deleted the upgrade-webpack-5 branch November 1, 2020 01:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Automatically merge PR once checks pass hacktoberfest-accepted
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants