@@ -39,6 +39,51 @@ can adopt modern async APIs from the ecosystem without hacks**.
3939 Note: ` Encore.getWebpackConfig() ` is now ** async** and returns a ` Promise ` . Use ` await ` at the
4040 top level of your webpack config (webpack supports async config files natively).
4141
42+ * If you prefer not to add ` "type": "module" ` to your project, you can rename your webpack config
43+ file to ` webpack.config.mjs ` instead. Webpack detects the ` .mjs ` extension and treats it as ESM
44+ automatically — no other changes needed.
45+
46+ * Replace ` __dirname ` and ` __filename ` with their ESM equivalents in your webpack config:
47+ ``` js
48+ // Before (CJS)
49+ path .resolve (__dirname , ' src/utilities/' )
50+ config: [__filename ]
51+
52+ // After (ESM)
53+ path .resolve (import .meta.dirname, ' src/utilities/' )
54+ config: [import .meta.filename]
55+ ` ` `
56+
57+ * Replace ` require ()` calls in your webpack config with ` import ` statements:
58+ ` ` ` js
59+ // Before (CJS)
60+ const path = require (' path' );
61+
62+ // After (ESM)
63+ import path from ' path' ;
64+ ` ` `
65+ If you need to require a CJS-only package, use ` createRequire` :
66+ ` ` ` js
67+ import { createRequire } from ' module' ;
68+ const require = createRequire (import .meta.url);
69+ const somePackage = require (' cjs-only-package' );
70+ ` ` `
71+
72+ * Config files that use CJS syntax (` module .exports ` , ` require ()` ) must be renamed to ` .cjs ` if
73+ your project has ` " type" : " module" ` in its ` package .json ` . This affects files such as:
74+ - ` postcss .config .js ` → ` postcss .config .cjs `
75+ - ` babel .config .js ` → ` babel .config .cjs `
76+
77+ Alternatively, rewrite them as ESM:
78+ ` ` ` js
79+ // postcss.config.js (ESM)
80+ export default {
81+ plugins: {
82+ autoprefixer: {},
83+ },
84+ };
85+ ` ` `
86+
4287* The package ` " exports" ` field is now restrictive: only ` " @symfony/webpack-encore" ` and
4388 ` " @symfony/webpack-encore/lib/plugins/plugin-priorities.js" ` are exposed as public entry points.
4489 If you were importing other internal modules directly, those imports will no longer work.
0 commit comments