posthtml-loader
posthtml-loader copied to clipboard
require() is not a function
On using plugins with the posthtml-loader using a posthtml.config.js or stating the configuration directly in the webpack.config.js, I constantly get a TypeError: require(...) is not a function.
- ModuleBuildError: Module build failed (from ../node_modules/posthtml-loader/lib/index.js):
- PostHTML Loader:
- require(...) is not a function
❌ Error (Logs|Stacks)
Using posthtml.config.js:
TypeError: require(...) is not a function at load (/home/apollo/posthtml-loader-require-bug/node_modules/posthtml-load-config/lib/plugins.js:40:31) at /home/apollo/posthtml-loader-require-bug/node_modules/posthtml-load-config/lib/plugins.js:51:18 at Array.forEach (
) at plugins (/home/apollo/posthtml-loader-require-bug/node_modules/posthtml-load-config/lib/plugins.js:50:8) at /home/apollo/posthtml-loader-require-bug/node_modules/posthtml-load-config/index.js:66:18 TypeError: Cannot read properties of undefined (reading 'default') at /home/apollo/posthtml-loader-require-bug/node_modules/posthtml-load-config/lib/plugins.js:53:20 at Array.forEach ( ) at plugins (/home/apollo/posthtml-loader-require-bug/node_modules/posthtml-load-config/lib/plugins.js:50:8) at /home/apollo/posthtml-loader-require-bug/node_modules/posthtml-load-config/index.js:66:18 TypeError: require(...) is not a function at load (/home/apollo/posthtml-loader-require-bug/node_modules/posthtml-load-config/lib/plugins.js:40:31) at /home/apollo/posthtml-loader-require-bug/node_modules/posthtml-load-config/lib/plugins.js:51:18 at Array.forEach ( ) at plugins (/home/apollo/posthtml-loader-require-bug/node_modules/posthtml-load-config/lib/plugins.js:50:8) at /home/apollo/posthtml-loader-require-bug/node_modules/posthtml-load-config/index.js:66:18 TypeError: Cannot read properties of undefined (reading 'default') at /home/apollo/posthtml-loader-require-bug/node_modules/posthtml-load-config/lib/plugins.js:53:20 at Array.forEach ( ) at plugins (/home/apollo/posthtml-loader-require-bug/node_modules/posthtml-load-config/lib/plugins.js:50:8) at /home/apollo/posthtml-loader-require-bug/node_modules/posthtml-load-config/index.js:66:18
Using webpack.config.js
ERROR in ./index.html Module build failed (from ./node_modules/posthtml-loader/lib/index.js): PostHTML Loader:
require(...) is not a function
at /home/apollo/posthtml-loader-require-bug/node_modules/posthtml-loader/lib/index.js:158:10@ ./index.js 1:0-32
ERROR in Error: Child compilation failed: Module build failed (from ./node_modules/posthtml-loader/lib/index.js): PostHTML Loader:
require(...) is not a function
at /home/apollo/posthtml-loader-require-bug/node_modules/posthtml-loader/lib/index.js:158:10ModuleBuildError: Module build failed (from ./node_modules/posthtml-loader/lib/index.js): PostHTML Loader:
require(...) is not a function
at /home/apollo/posthtml-loader-require-bug/node_modules/posthtml-loader/lib/index.js:158:10 at processResult (/home/apollo/posthtml-loader-require-bug/node_modules/webpack/lib/NormalModule.js:753:19) at /home/apollo/posthtml-loader-require-bug/node_modules/webpack/lib/NormalModule.js:855:5 at /home/apollo/posthtml-loader-require-bug/node_modules/loader-runner/lib/LoaderRunner.js:399:11 at /home/apollo/posthtml-loader-require-bug/node_modules/loader-runner/lib/LoaderRunner.js:251:18 at context.callback (/home/apollo/posthtml-loader-require-bug/node_modules/loader-runner/lib/LoaderRunner.js:124:13) at /home/apollo/posthtml-loader-require-bug/node_modules/posthtml-loader/lib/index.js:158:7
index.js:158 [posthtml-loader-require-bug]/[posthtml-loader]/lib/index.js:158:10
ModuleBuildError: Module build failed (from ./node_modules/posthtml-loader/lib/index.js):
PostHTML Loader:
require(...) is not a function
index.js:158 [posthtml-loader-require-bug]/[posthtml-loader]/lib/index.js:158:10
NormalModule.js:753 processResult [posthtml-loader-require-bug]/[webpack]/lib/NormalModule.js:753:19
NormalModule.js:855 [posthtml-loader-require-bug]/[webpack]/lib/NormalModule.js:855:5
LoaderRunner.js:399 [posthtml-loader-require-bug]/[loader-runner]/lib/LoaderRunner.js:399:11
LoaderRunner.js:251 [posthtml-loader-require-bug]/[loader-runner]/lib/LoaderRunner.js:251:18
LoaderRunner.js:124 context.callback [posthtml-loader-require-bug]/[loader-runner]/lib/LoaderRunner.js:124:13
index.js:158 [posthtml-loader-require-bug]/[posthtml-loader]/lib/index.js:158:7
child-compiler.js:169 [posthtml-loader-require-bug]/[html-webpack-plugin]/lib/child-compiler.js:169:18
Compiler.js:564 [posthtml-loader-require-bug]/[webpack]/lib/Compiler.js:564:11
Compiler.js:1183 [posthtml-loader-require-bug]/[webpack]/lib/Compiler.js:1183:17
Hook.js:18 Hook.CALL_ASYNC_DELEGATE [as _callAsync] [posthtml-loader-require-bug]/[tapable]/lib/Hook.js:18:14
Compiler.js:1179 [posthtml-loader-require-bug]/[webpack]/lib/Compiler.js:1179:33
Compilation.js:2785 finalCallback [posthtml-loader-require-bug]/[webpack]/lib/Compilation.js:2785:11
Compilation.js:3090 [posthtml-loader-require-bug]/[webpack]/lib/Compilation.js:3090:11
Hook.js:18 Hook.CALL_ASYNC_DELEGATE [as _callAsync] [posthtml-loader-require-bug]/[tapable]/lib/Hook.js:18:14
1 ERROR in child compilations (Use 'stats.children: true' resp. '--stats-children' for more details) webpack 5.69.0 compiled with 3 errors in 1679 ms
♻️ Reproduction (Code)
git clone https://github.com/azan-n/posthtml-loader-require-bug
🌐 Environment
html-loader: "^3.1.0" posthtml: "^0.15.2" webpack: "^5.69.0" webpack-cli: "^4.9.2"
| OS | node | npm/yarn | package |
|---|---|---|---|
| [Ubuntu 20.04.3 LTS] | [v16.13.0] | [8.1.4] | [^2.0.1] |