nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.58k stars 2.36k forks source link

importing `less` files from node_modules is causing a `ModuleBuildError` #1935

Closed geocine closed 4 years ago

geocine commented 5 years ago

I am integrating antd with next.js. I have followed working example outside of the Nx workspace written in JavaScript.

Setup is based on this working example from zeit https://github.com/zeit/next.js/tree/master/examples/with-ant-design-less

I have created the same example in Nx Workspace but in TypeScript

Expected Behavior

Project should successfully work inside Nx Workspace

Current Behavior

It is currently throwing an error regarding less

[ error ] /Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/antd/lib/form/style/index.less
Error: Didn't get a result from child compiler

See full error below

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. Create empty Nx workspace
  2. Add next.js application and use less as style
  3. Copy how this is setup https://github.com/zeit/next.js/tree/master/examples/with-ant-design-less
  4. Run the application

Context

I have created a repo to reproduce the issue

https://github.com/geocine/nx-antd-less-typescript-issue

nx serve nx-antd

Failure Logs

[ error ] /Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/antd/lib/form/style/index.less
Error: Didn't get a result from child compiler
ModuleBuildError: Module build failed (from /Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/@zeit/next-css/node_modules/mini-css-extract-plugin/dist/loader.js):
ModuleBuildError: Module build failed (from /Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/@zeit/next-css/node_modules/mini-css-extract-plugin/dist/loader.js):
Error: Didn't get a result from child compiler
    at childCompiler.runAsChild (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/@zeit/next-css/node_modules/mini-css-extract-plugin/dist/loader.js:121:23)
    at compile (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/next/node_modules/webpack/lib/Compiler.js:343:11)
    at hooks.afterCompile.callAsync.err (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/next/node_modules/webpack/lib/Compiler.js:671:15)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:33:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/tapable/lib/Hook.js:154:20)
    at compilation.seal.err (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/next/node_modules/webpack/lib/Compiler.js:668:31)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/tapable/lib/Hook.js:154:20)
    at hooks.optimizeAssets.callAsync.err (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/next/node_modules/webpack/lib/Compilation.js:1385:35)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/tapable/lib/Hook.js:154:20)
    at hooks.optimizeChunkAssets.callAsync.err (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/next/node_modules/webpack/lib/Compilation.js:1376:32)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/tapable/lib/Hook.js:154:20)
    at hooks.additionalAssets.callAsync.err (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/next/node_modules/webpack/lib/Compilation.js:1371:36)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at runLoaders (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/next/node_modules/webpack/lib/NormalModule.js:313:20)
    at /Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/loader-runner/lib/LoaderRunner.js:367:11
    at /Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/loader-runner/lib/LoaderRunner.js:182:20
    at context.callback (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
    at childCompiler.runAsChild (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/@zeit/next-css/node_modules/mini-css-extract-plugin/dist/loader.js:121:14)
    at compile (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/next/node_modules/webpack/lib/Compiler.js:343:11)
    at hooks.afterCompile.callAsync.err (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/next/node_modules/webpack/lib/Compiler.js:671:15)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:33:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/tapable/lib/Hook.js:154:20)
    at compilation.seal.err (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/next/node_modules/webpack/lib/Compiler.js:668:31)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/tapable/lib/Hook.js:154:20)
    at hooks.optimizeAssets.callAsync.err (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/next/node_modules/webpack/lib/Compilation.js:1385:35)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/tapable/lib/Hook.js:154:20)
    at hooks.optimizeChunkAssets.callAsync.err (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/next/node_modules/webpack/lib/Compilation.js:1376:32)
    at runLoaders (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/next/node_modules/webpack/lib/NormalModule.js:313:20)
    at /Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/loader-runner/lib/LoaderRunner.js:367:11
    at /Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/loader-runner/lib/LoaderRunner.js:182:20
    at context.callback (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
    at childCompiler.runAsChild (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/@zeit/next-css/node_modules/mini-css-extract-plugin/dist/loader.js:112:14)
    at compile (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/next/node_modules/webpack/lib/Compiler.js:343:11)
    at hooks.afterCompile.callAsync.err (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/next/node_modules/webpack/lib/Compiler.js:671:15)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:24:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/tapable/lib/Hook.js:154:20)
    at compilation.seal.err (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/next/node_modules/webpack/lib/Compiler.js:668:31)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/tapable/lib/Hook.js:154:20)
    at hooks.optimizeAssets.callAsync.err (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/next/node_modules/webpack/lib/Compilation.js:1385:35)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/tapable/lib/Hook.js:154:20)
    at hooks.optimizeChunkAssets.callAsync.err (/Users/aivan/Desktop/PL/nx-antd-less-typescript-issue/node_modules/next/node_modules/webpack/lib/Compilation.js:1376:32)
Driky commented 4 years ago

@geocine any news on antd integration with next inside nx ?

basilenouvellet commented 4 years ago

Running into the same issue here, any update on this?

jdpearce commented 4 years ago

Upgrading to the latest version of Nx and also installing the null-loader that you reference seems to fix this. It may be that you were just missing the null-loader in the first place, but that was the second thing I tried after upgrading 🤷‍♀️

For ref, to upgrade:

yarn add @nrwl/workspace@latest nx migrate 9.3.0 --from=@nrwl/workspace@8.6.0 yarn nx migrate --run-migrations=migrations.json yarn add null-loader

Update your workspace.json so that the serve builder is now @nrwl/next:server, then:

nx serve nx-antd

Let me know if you still have problems after trying that.

github-actions[bot] commented 1 year ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.