两极距离 發表於 2020-9-2 09:41:00

Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js): ReferenceError: document is not defined

<div class="cnblogs_Highlighter">
<pre class="brush:javascript;gutter:true;">Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
ReferenceError: document is not defined
    at insertStyleElement (E:\webs\test\node_modules\style-loader\dist\cjs.js!E:\webs\test\node_modules\css-loader\dist\cjs.js!E:\webs\test\node_modules\postcss-loader\src\index.js??ref--4-3!E:\webs\test\node_modules\stylus-loader\index.js!E:\webs\test\client\assets\styles\footer.styl:309:15)
    at addStyle (E:\webs\test\node_modules\style-loader\dist\cjs.js!E:\webs\test\node_modules\css-loader\dist\cjs.js!E:\webs\test\node_modules\postcss-loader\src\index.js??ref--4-3!E:\webs\test\node_modules\stylus-loader\index.js!E:\webs\test\client\assets\styles\footer.styl:424:13)
    at modulesToDom (E:\webs\test\node_modules\style-loader\dist\cjs.js!E:\webs\test\node_modules\css-loader\dist\cjs.js!E:\webs\test\node_modules\postcss-loader\src\index.js??ref--4-3!E:\webs\test\node_modules\stylus-loader\index.js!E:\webs\test\client\assets\styles\footer.styl:297:18)
    at module.exports.module.exports (E:\webs\test\node_modules\style-loader\dist\cjs.js!E:\webs\test\node_modules\css-loader\dist\cjs.js!E:\webs\test\node_modules\postcss-loader\src\index.js??ref--4-3!E:\webs\test\node_modules\stylus-loader\index.js!E:\webs\test\client\assets\styles\footer.styl:455:25)
    at Object.&lt;anonymous&gt; (E:\webs\test\node_modules\style-loader\dist\cjs.js!E:\webs\test\node_modules\css-loader\dist\cjs.js!E:\webs\test\node_modules\postcss-loader\src\index.js??ref--4-3!E:\webs\test\node_modules\stylus-loader\index.js!E:\webs\test\client\assets\styles\footer.styl:206:14)
    at __webpack_require__ (E:\webs\test\node_modules\style-loader\dist\cjs.js!E:\webs\test\node_modules\css-loader\dist\cjs.js!E:\webs\test\node_modules\postcss-loader\src\index.js??ref--4-3!E:\webs\test\node_modules\stylus-loader\index.js!E:\webs\test\client\assets\styles\footer.styl:21:30)
    at E:\webs\test\node_modules\style-loader\dist\cjs.js!E:\webs\test\node_modules\css-loader\dist\cjs.js!E:\webs\test\node_modules\postcss-loader\src\index.js??ref--4-3!E:\webs\test\node_modules\stylus-loader\index.js!E:\webs\test\client\assets\styles\footer.styl:85:18
    at Object.&lt;anonymous&gt; (E:\webs\test\node_modules\style-loader\dist\cjs.js!E:\webs\test\node_modules\css-loader\dist\cjs.js!E:\webs\test\node_modules\postcss-loader\src\index.js??ref--4-3!E:\webs\test\node_modules\stylus-loader\index.js!E:\webs\test\client\assets\styles\footer.styl:88:10)
    at Module._compile (E:\webs\test\node_modules\v8-compile-cache\v8-compile-cache.js:194:30)
    at evalModuleCode (E:\webs\test\node_modules\mini-css-extract-plugin\dist\loader.js:66:10)
    at E:\webs\test\node_modules\mini-css-extract-plugin\dist\loader.js:196:31
    at E:\webs\test\node_modules\webpack\lib\Compiler.js:343:11
    at E:\webs\test\node_modules\webpack\lib\Compiler.js:681:15
    at AsyncSeriesHook.eval (eval at create (E:\webs\test\node_modules\tapable\lib\HookCodeFactory.js:33:10), &lt;anonymous&gt;:15:1)
    at AsyncSeriesHook.lazyCompileHook (E:\webs\test\node_modules\tapable\lib\Hook.js:154:20)
    at E:\webs\test\node_modules\webpack\lib\Compiler.js:678:31
    at AsyncSeriesHook.eval (eval at create (E:\webs\test\node_modules\tapable\lib\HookCodeFactory.js:33:10), &lt;anonymous&gt;:6:1)
    at AsyncSeriesHook.lazyCompileHook (E:\webs\test\node_modules\tapable\lib\Hook.js:154:20)
    at E:\webs\test\node_modules\webpack\lib\Compilation.js:1423:35
    at AsyncSeriesHook.eval (eval at create (E:\webs\test\node_modules\tapable\lib\HookCodeFactory.js:33:10), &lt;anonymous&gt;:6:1)
    at AsyncSeriesHook.lazyCompileHook (E:\webs\test\node_modules\tapable\lib\Hook.js:154:20)
    at E:\webs\test\node_modules\webpack\lib\Compilation.js:1414:32
    at eval (eval at create (E:\webs\test\node_modules\tapable\lib\HookCodeFactory.js:33:10), &lt;anonymous&gt;:11:1)
    at E:\webs\test\node_modules\terser-webpack-plugin\dist\index.js:321:9
    at TaskRunner.run (E:\webs\test\node_modules\terser-webpack-plugin\dist\TaskRunner.js:48:7)
    at TerserPlugin.optimizeFn (E:\webs\test\node_modules\terser-webpack-plugin\dist\index.js:227:18)
    at AsyncSeriesHook.eval (eval at create (E:\webs\test\node_modules\tapable\lib\HookCodeFactory.js:33:10), &lt;anonymous&gt;:7:1)
    at AsyncSeriesHook.lazyCompileHook (E:\webs\test\node_modules\tapable\lib\Hook.js:154:20)
    at E:\webs\test\node_modules\webpack\lib\Compilation.js:1409:36
    at AsyncSeriesHook.eval (eval at create (E:\webs\test\node_modules\tapable\lib\HookCodeFactory.js:33:10), &lt;anonymous&gt;:6:1)
    at AsyncSeriesHook.lazyCompileHook (E:\webs\test\node_modules\tapable\lib\Hook.js:154:20)
    at E:\webs\test\node_modules\webpack\lib\Compilation.js:1405:32
    at AsyncSeriesHook.eval (eval at create (E:\webs\test\node_modules\tapable\lib\HookCodeFactory.js:33:10), &lt;anonymous&gt;:6:1)
    at AsyncSeriesHook.lazyCompileHook (E:\webs\test\node_modules\tapable\lib\Hook.js:154:20)
    at Compilation.seal (E:\webs\test\node_modules\webpack\lib\Compilation.js:1342:27)
</pre>
</div>
<p> 搞了一个下午,原来是加多了style-loader</p>
<div class="cnblogs_Highlighter">
<pre class="brush:javascript;gutter:true;">{
    test: /\.styl$/,
    use: [
      MiniCssExtractPlugin.loader,
      'style-loader', //要删除这个loader,不然一直报错
      'css-loader',
      {
      loader: 'postcss-loader',
      options: {
          sourceMap: true
      }
      },
      'stylus-loader'
    ]
}
</pre>
</div>
<p>  </p>
<p> </p><br><br>
来源:https://www.cnblogs.com/baidei/p/13600094.html
頁: [1]
查看完整版本: Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js): ReferenceError: document is not defined