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

Webpack 5 support #13341

Closed
13 tasks done
timneutkens opened this issue May 25, 2020 · 68 comments
Closed
13 tasks done

Webpack 5 support #13341

timneutkens opened this issue May 25, 2020 · 68 comments
Assignees
Milestone

Comments

@timneutkens
Copy link
Member

timneutkens commented May 25, 2020

Follow-up of #9426, opening this as the overarching issue on what to solve:

@todortotev
Copy link
Contributor

@timneutkens If there is anything you would let a non-maintainer help with, I'd be glad to assist.

@arzafran
Copy link

Having the following error, but probably it's related to Theme-UI and they should support Webpack 5

error - ./node_modules/@theme-ui/core/dist/index.esm.js
Should not import the named export 'version' (imported as 'version') from default-exporting module (only default export is available soon)

It should be a fairly simple fix, but I think it may trigger a chain of fixes needed on other dependencies. we would have to manually change all these from:

import { version } from './package.json';	
export default version;	

to

import packageInfo from './package.json';
export default packageInfo.version;

right?

@dvakatsiienko
Copy link
Contributor

Having the following error, but probably it's related to Theme-UI and they should support Webpack 5

error - ./node_modules/@theme-ui/core/dist/index.esm.js
Should not import the named export 'version' (imported as 'version') from default-exporting module (only default export is available soon)

It should be a fairly simple fix, but I think it may trigger a chain of fixes needed on other dependencies. we would have to manually change all these from:

import { version } from './package.json';	
export default version;	

to

import packageInfo from './package.json';
export default packageInfo.version;

right?

Same error happens to AWS-amplify library.

@imagentleman
Copy link
Contributor

Having issues in ie11.

Was able to reproduce with a brand new app created with create-next-app.

Error:

I get a blank page showing this on the console:

Screen Shot 2020-07-29 at 3 02 30 PM

Steps to reproduce:

  1. Install yarn 1.22.4 and node v12.14.1 on MacOS 10.15.6
  2. Run yarn create next-app as shown on https://nextjs.org/docs
  3. Run yarn dev
  4. Open localhost:3000 (or 10.0.2.2:3000) in ie11 (v11.1339.17763.0) with a win10 image running on virtual box 6.1.12 r139181

Notes:
Doesn't seem to happen with next.js 9.4.0, next.js 9.4.4 or next.js 9.5.0 in production mode (after running yarn build and yarn start).

Didn't add { "resolutions": { "webpack": "^5.0.0-beta.22" } } to enable webpack 5. But it also happens with it.
On a real windows device (with similar software installed: win10, ie11, yarn, etc) i'm only getting the first colon error, but everything seems to work (initial page load, fast refresh, etc) unlike with the mac and vm combo. 🤷‍♂️

@timneutkens
Copy link
Member Author

Didn't add { "resolutions": { "webpack": "^5.0.0-beta.22" } } to enable webpack 5

Then this is off topic, please create a new issue.

@valse
Copy link
Contributor

valse commented Jul 30, 2020

Hi, I'm trying to add the webpack 5 beta too but I have this error on compilation:

Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema
configuration[0].module.rules[2].issuer has an unknown property 'test'. These properties are valid

I have no custom webpack config and I'm using styled-jsx with styled-jsx-plugin-sass too

@timneutkens
Copy link
Member Author

Hi, I'm trying to add the webpack 5 beta too but I have this error on compilation:

Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema
configuration[0].module.rules[2].issuer has an unknown property 'test'. These properties are valid

I have no custom webpack config and I'm using styled-jsx with styled-jsx-plugin-sass too

Are you sure you don't have anything in next.config.js, it's practically impossible for this error to occur if you do not have custom webpack configuration, this could be through added plugins.

@valse
Copy link
Contributor

valse commented Jul 30, 2020

Hi, I'm trying to add the webpack 5 beta too but I have this error on compilation:
Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema
configuration[0].module.rules[2].issuer has an unknown property 'test'. These properties are valid
I have no custom webpack config and I'm using styled-jsx with styled-jsx-plugin-sass too

Are you sure you don't have anything in next.config.js, it's practically impossible for this error to occur if you do not have custom webpack configuration, this could be through added plugins.

Hi @timneutkens, this is my next.config.js and you're right I'm using the 'next-images' plugin:

const withImages = require("next-images")

module.exports = withImages({
  esModule: true,
  trailingSlash: false,
  env: {
    ...
  },
})

@timneutkens
Copy link
Member Author

So that likely edits the webpack config in a wrong way which is a bug in that library.

@valse
Copy link
Contributor

valse commented Jul 30, 2020

So that likely edits the webpack config in a wrong way which is a bug in that library.

Yes it is: switching to the next-optimized-images plugin all works as expected... I open an issue for the next-images plugin. Thanks!

@Utwo
Copy link

Utwo commented Jul 30, 2020

How can I test this with npm instead of yarn?

@timneutkens
Copy link
Member Author

How can I test this with npm instead of yarn?

You can't currently because npm does not support resolutions afaik.

@zburk
Copy link

zburk commented Jul 31, 2020

Running webpack 5, everything still works for me with the following deprecation warnings. Creating a new nextjs app, I get the same deprecation warnings.

(node:85371) [DEP_WEBPACK_EXTERNALS_FUNCTION_PARAMETERS] DeprecationWarning: The externals-function should be defined like ({context, request}, cb) => { ... }
(node:85371) [DEP_WEBPACK_COMPILATION_ASSETS] DeprecationWarning: Compilation.assets will be frozen in future, all modifications are deprecated.
BREAKING CHANGE: No more changes should happen to Compilation.assets after sealing the Compilation.
Do changes to assets earlier, e. g. in Compilation.hooks.processAssets.
Make sure to select an appropriate stage from Compilation.PROCESS_ASSETS_STAGE_*.
(node:85371) [DEP_WEBPACK_DEPRECATION_ARRAY_TO_SET] DeprecationWarning: Compilation.chunks was changed from Array to Set (using Array method 'find' is deprecated)
(node:85371) [DEP_WEBPACK_CHUNK_MODULES_ITERABLE] DeprecationWarning: Chunk.modulesIterable: Use new ChunkGraph API
(node:85371) [DEP_WEBPACK_MODULE_ID] DeprecationWarning: Module.id: Use new ChunkGraph API
"dependencies": {
    "fs-extra": "^9.0.1",
    "lodash": "^4.17.19",
    "next": "9.5.0",
    "next-pwa": "^3.1.1",
    "react": "16.13.1",
    "react-burger-menu": "^2.7.0",
    "react-dom": "16.13.1",
    "react-notifications-component": "^2.4.0",
    "react-redux": "^7.2.1",
    "redux": "^4.0.5",
    "redux-devtools-extension": "^2.13.8",
    "redux-persist": "^6.0.0",
    "redux-thunk": "^2.3.0",
    "socket.io-client": "^2.3.0",
    "styled-components": "^5.1.1",
    "swr": "^0.2.3"
  },
  "devDependencies": {
    "@babel/cli": "^7.10.5",
    "@babel/preset-env": "^7.10.4",
    "@types/lodash": "^4.14.158",
    "@types/node": "^14.0.26",
    "@types/react": "^16.9.43",
    "@types/react-burger-menu": "^2.6.1",
    "@types/react-notifications-component": "^2.4.0",
    "@types/react-redux": "^7.1.9",
    "@types/socket.io-client": "^1.4.33",
    "@types/styled-components": "^5.1.1",
    "babel-plugin-lodash": "^3.3.4",
    "babel-plugin-styled-components": "^1.10.7",
    "eslint": "^7.5.0",
    "eslint-plugin-react": "^7.20.5",
    "postcss-preset-env": "^6.7.0",
    "redux-devtools": "^3.5.0",
    "tailwindcss": "^1.5.2",
    "typescript": "^3.9.7"
  },

@timneutkens
Copy link
Member Author

@sebinsua persistent caching is configured in the latest canary. It still needs some improvements but initial results are great.

@jasonwilliams
Copy link

@timneutkens I hope this isn’t a silly question. How do we try out webpack 5 with this? Do we change resolutions in package.json? Or is there some flag to pass?

@timneutkens
Copy link
Member Author

https://nextjs.org/blog/next-9-5#webpack-5-support-beta

Adding resolutions and potentially using the latest next@canary 👍

@purecopy
Copy link

Are there any suggestions on how to enable webpack 5 in combination with yarn workspaces? Since the resolutions feature only works in the top level package.json, I would not be able to use any other webpack versions. (e.g CRA still relies on webpack 4). Am I missing something?

@Toolo
Copy link

Toolo commented Oct 30, 2020

+1 to @jonawww

We have a monorepo with several apps, some of them are in the process of being migrated to webpack 5 (but they still depend on webpack 4) and then we have the NextJS app, so we can't rely on the top level resolutions. Is there any other way via configuration to switch to webpack 5?

Thanks

@sokra
Copy link
Member

sokra commented Oct 30, 2020

resolutions also supports partial overrides e.g. "myapp/**/webpack": "^5.3.1". See yarn documentation for details.

@Toolo
Copy link

Toolo commented Oct 30, 2020

@sokra thanks for the hint! I will definitely try it out 😃

@purecopy
Copy link

purecopy commented Oct 31, 2020

@sokra This did the trick, thanks a lot! 🙌

Edit: Seems like I was a little too hasty 😅 in my case I had to override it like "**/myapp/**/webpack": "^5.3.2"

@Xerkus
Copy link

Xerkus commented Nov 2, 2020

Note that glob patterns are not allowed with yarn 2.
From yarn install:

The override for '**/webpack' includes a glob pattern. Glob patterns have been removed since their behaviours don't match what you'd expect. Set the override to 'webpack' instead.

@aralroca
Copy link
Contributor

In my case adding the resolutions I got this warning:

warning Resolution field "[email protected]" is incompatible with requested version "[email protected]"

image

And checking require('webpack').version is 4.44.1 😅 Anyone knows what this could happen? Thanks!

@outerlook
Copy link

outerlook commented Nov 25, 2020

And checking require('webpack').version is 4.44.1 😅 Anyone knows what this could happen? Thanks!

same as @aralroca while using yarn workspaces and
"**/frontend/**/webpack": "5.6.0"
at project-root > package.json > resolutions

@gajus
Copy link

gajus commented Nov 26, 2020

If anyone is struggling with getting rid of webpack v4 from the dependency tree while using NPM v7, I've documented a solution:

#!/usr/bin/env node

/* eslint-disable unicorn/prevent-abbreviations */
/* eslint-disable import/unambiguous */
/* eslint-disable import/no-commonjs */
/* eslint-disable node/shebang */

const fs = require('fs').promises;
const path = require('path');

const main = async (resolutions) => {
  const packageLockFilePath = path.resolve(__dirname, '../package-lock.json');

  for (const [name, version] of Object.entries(resolutions)) {
    const packageLock = JSON.parse(await fs.readFile(packageLockFilePath));

    const packagePaths = Object.keys(packageLock.packages);

    const deletePaths = [];

    for (const packagePath of packagePaths) {
      if (packagePath.endsWith('/' + name)) {
        if (packageLock.packages[packagePath].version !== version) {
          deletePaths.push(packagePath);
        }
      }
    }

    for (const packagePath of deletePaths) {
      for (const deletePath of deletePaths) {
        if (packagePath === deletePath || packagePath.startsWith(deletePath + '/')) {
          // eslint-disable-next-line fp/no-delete
          delete packageLock.packages[packagePath];
        }
      }
    }

    await fs.writeFile(
      packageLockFilePath,
      JSON.stringify(packageLock, null, '  '),
    );
  }
};

main(require('../package.json').resolutions);

Explanation in the Stack Overflow answer:

https://stackoverflow.com/a/65014694/368691

@shobhitsharma
Copy link

@Xerkus @outerlook @gajus Ran into same issue, got storybook running in monorepo which doesnt support webpack v5 yet, since yarn v2 **/ glob patterns wont be allowed, is there any way to resolve it alternatively.

I saw yarn workspaces has nohoist (see here), I've been trying it out but no luck.

@ujwal-setlur
Copy link

I just tried out Webpack 5 on a next's 10.0.3 project. Build time seemed to actually increase:

with Webpack 4:

Executed in  151.61 secs   fish           external 
   usr time  230.24 secs  125.00 micros  230.24 secs 
   sys time   13.69 secs  625.00 micros   13.69 secs 

with Webpack 5:

Executed in  167.02 secs   fish           external 
   usr time  492.86 secs  161.00 micros  492.86 secs 
   sys time   69.28 secs  906.00 micros   69.28 secs 

I should expect faster build times, no?

I also saw a JavaScript OOM exception once:

info  - Using external babel configuration from /Users/ujwal/Work/byte/software/repos/micro/dashboard/.babelrc
info  - Creating an optimized production build .
<--- Last few GCs --->

[1332:0x110008000]   149669 ms: Mark-sweep 2014.8 (2101.4) -> 2014.7 (2060.6) MB, 993.7 / 0.0 ms  (average mu = 0.233, current mu = 0.000) last resort GC in old space requested
[1332:0x110008000]   150693 ms: Mark-sweep 2014.7 (2060.6) -> 2014.7 (2055.6) MB, 1023.7 / 0.0 ms  (average mu = 0.125, current mu = 0.000) last resort GC in old space requested


<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 0x1009dcbd9]
    1: StubFrame [pc: 0x100a1900f]
Security context: 0x2050d0a408d1 <JSObject>
    2: replace [0x2050d0a4cc71](this=0x205134b80119 <Very long string[67684575]>,0x2050f12cb1e9 <JSRegExp <String[67]: (\\)?"@__(F|R|D|M|S|U|I|B)-b8a6f9ee4b77bb1b764a3bb3b52e1c-(\d+)__@">>,0x2050b395ca99 <JSFunction (sfi = 0x2050ee27c689)>)
    3: serialize(aka serialize) [0x20502fa272b9] [/Users/ujwal/Work/byte/software/repos...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: 0x1011d1cc5 node::Abort() (.cold.1) [/var/folders/yg/8_rbwqbx51b5xn2_93_y43y00000gn/T/fnm_multishell_75535_1608360666435/bin/node]
 2: 0x10009f919 node::Abort() [/var/folders/yg/8_rbwqbx51b5xn2_93_y43y00000gn/T/fnm_multishell_75535_1608360666435/bin/node]
 3: 0x10009fa7f node::OnFatalError(char const*, char const*) [/var/folders/yg/8_rbwqbx51b5xn2_93_y43y00000gn/T/fnm_multishell_75535_1608360666435/bin/node]
 4: 0x1001e38b7 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/var/folders/yg/8_rbwqbx51b5xn2_93_y43y00000gn/T/fnm_multishell_75535_1608360666435/bin/node]
 5: 0x1001e3857 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/var/folders/yg/8_rbwqbx51b5xn2_93_y43y00000gn/T/fnm_multishell_75535_1608360666435/bin/node]
 6: 0x10036b9e5 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/var/folders/yg/8_rbwqbx51b5xn2_93_y43y00000gn/T/fnm_multishell_75535_1608360666435/bin/node]
 7: 0x100373a8c v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/var/folders/yg/8_rbwqbx51b5xn2_93_y43y00000gn/T/fnm_multishell_75535_1608360666435/bin/node]
 8: 0x10033fe0d v8::internal::Factory::NewFixedArrayWithFiller(v8::internal::RootIndex, int, v8::internal::Object, v8::internal::AllocationType) [/var/folders/yg/8_rbwqbx51b5xn2_93_y43y00000gn/T/fnm_multishell_75535_1608360666435/bin/node]
 9: 0x100710002 v8::internal::FixedArrayBuilder::EnsureCapacity(v8::internal::Isolate*, int) [/var/folders/yg/8_rbwqbx51b5xn2_93_y43y00000gn/T/fnm_multishell_75535_1608360666435/bin/node]
10: 0x1006bb42b v8::internal::Runtime_RegExpExecMultiple(int, unsigned long*, v8::internal::Isolate*) [/var/folders/yg/8_rbwqbx51b5xn2_93_y43y00000gn/T/fnm_multishell_75535_1608360666435/bin/node]
11: 0x1009dcbd9 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit [/var/folders/yg/8_rbwqbx51b5xn2_93_y43y00000gn/T/fnm_multishell_75535_1608360666435/bin/node]
sh: line 1:  1332 Abort trap: 6           next build
npm ERR! code ELIFECYCLE
npm ERR! errno 134
npm ERR! [email protected] build: `npm run clean && next build`
npm ERR! Exit status 134
npm ERR! 
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/ujwal/.npm/_logs/2020-12-21T18_59_02_529Z-debug.log

@hvqzao
Copy link

hvqzao commented Apr 11, 2021

when

future: {
   webpack5: true
}

Next seems to partially ignore

  distDir: 'sth'

and creates some files in .next/cache/webpack/ directory.

@timneutkens
Copy link
Member Author

That's fixed already on next@canary.

@SalahAdDin

This comment has been minimized.

@timakhalaya

This comment has been minimized.

@outerlook

This comment has been minimized.

@timakhalaya

This comment has been minimized.

@tsusini

This comment has been minimized.

@Toolo

This comment has been minimized.

@timakhalaya

This comment has been minimized.

@timneutkens
Copy link
Member Author

#23498

@vercel vercel locked as resolved and limited conversation to collaborators Jun 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests