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

Support for default loader (file-loader) for unknown modules #7615

Closed
pravdomil opened this issue Jun 27, 2018 · 17 comments
Closed

Support for default loader (file-loader) for unknown modules #7615

pravdomil opened this issue Jun 27, 2018 · 17 comments
Labels

Comments

@pravdomil
Copy link

pravdomil commented Jun 27, 2018

Feature request

from facebook/create-react-app#667 (comment):

A catchall unknown-source loader feels like it would be pretty beneficial.
My opinion is that you want it managed by webpack in some way or another.

What is the expected behavior?

Non-javascript files without loader will be handled by file-loader, this can be configured in module.fallbackLoader.

What is motivation or use case for adding/changing the behavior?

Nowadays you need to list all of extensions yourself:

{
  test: /\.(json|css|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$/,
  loader: "file-loader",
}

How should this be implemented in your opinion?

// webpack.config.js

module.exports = {
  module: {
    fallbackLoader: {
      loader: "url-loader",
    }
  }
}

Are you willing to work on this yourself?
yes

@TheLarkInn
Copy link
Member

Should this be considered as a separate module type also? Something we may want to consider if no loaders applied.

@alexander-akait
Copy link
Member

@TheLarkInn looks already in maybe https://github.com/webpack/webpack/projects/5#card-10666456 for webpack@5

@sokra
Copy link
Member

sokra commented Jun 28, 2018

While I think it makes more sense to list all extensions explicitly you can do a default loaders with the oneOf construct in module.rules:

module.rules: [{
  oneOf: [
    { test: /\.js/, ... },
    { test: /\.ts/, ... },
    { use: "file-loader" }
  ]
}]

https://webpack.js.org/configuration/module/#rule-oneof

@pravdomil
Copy link
Author

pravdomil commented Jun 28, 2018

well that's clever but for some reason it doesn't work with mini-css-extract-plugin

ERROR in ./src/style.css
Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
TypeError: __webpack_require__(...) is not a function
webpack.config.js
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

module.exports = {
  module: {
    rules: [
      {
        oneOf: [
          {
            test: /\.js$/,
            exclude: /node_modules/,
            loader: "babel-loader"
          },
          {
            test: /\.css$/,
            use: [
              "mini-css-extract-plugin/dist/loader.js",
              "css-loader"
            ]
          },
          {
            use: "file-loader"
          }
        ]
      }
    ]
  },
  plugins: [new MiniCssExtractPlugin()]
};
src/index.js
import "./style.css";
stats.json
{
  "errors": [
    "./src/style.css\nModule build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):\nTypeError: __webpack_require__(...) is not a function\n    at Object.<anonymous> (./node_modules/css-loader/index.js!./src/style.css:98:50)\n    at __webpack_require__ (./node_modules/css-loader/index.js!./src/style.css:21:30)\n    at module.exports.module.exports (./node_modules/css-loader/index.js!./src/style.css:85:18)\n    at Object.<anonymous> (./node_modules/css-loader/index.js!./src/style.css:88:10)\n    at Module._compile (./node_modules/v8-compile-cache/v8-compile-cache.js:178:30)\n    at exec (./node_modules/mini-css-extract-plugin/dist/loader.js:55:10)\n    at childCompiler.runAsChild (./node_modules/mini-css-extract-plugin/dist/loader.js:133:14)\n    at compile (./node_modules/webpack/lib/Compiler.js:243:11)\n    at hooks.afterCompile.callAsync.err (./node_modules/webpack/lib/Compiler.js:500:14)\n    at AsyncSeriesHook.eval [as callAsync] (eval at create (./node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:15:1)\n    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (./node_modules/tapable/lib/Hook.js:35:21)\n    at compilation.seal.err (./node_modules/webpack/lib/Compiler.js:497:30)\n    at AsyncSeriesHook.eval [as callAsync] (eval at create (./node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:6:1)\n    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (./node_modules/tapable/lib/Hook.js:35:21)\n    at hooks.optimizeAssets.callAsync.err (./node_modules/webpack/lib/Compilation.js:995:35)\n    at AsyncSeriesHook.eval [as callAsync] (eval at create (./node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:6:1)\n    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (./node_modules/tapable/lib/Hook.js:35:21)\n    at hooks.optimizeChunkAssets.callAsync.err (./node_modules/webpack/lib/Compilation.js:986:32)\n    at _err0 (eval at create (./node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:11:1)\n    at ./node_modules/uglifyjs-webpack-plugin/dist/index.js:282:11\n    at _class.runTasks (./node_modules/uglifyjs-webpack-plugin/dist/uglify/index.js:63:9)\n    at UglifyJsPlugin.optimizeFn (./node_modules/uglifyjs-webpack-plugin/dist/index.js:195:16)\n    at AsyncSeriesHook.eval [as callAsync] (eval at create (./node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:7:1)\n    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (./node_modules/tapable/lib/Hook.js:35:21)\n    at hooks.additionalAssets.callAsync.err (./node_modules/webpack/lib/Compilation.js:981:36)\n    at AsyncSeriesHook.eval [as callAsync] (eval at create (./node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:6:1)\n    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (./node_modules/tapable/lib/Hook.js:35:21)\n    at hooks.optimizeTree.callAsync.err (./node_modules/webpack/lib/Compilation.js:977:32)\n    at AsyncSeriesHook.eval [as callAsync] (eval at create (./node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:6:1)\n    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (./node_modules/tapable/lib/Hook.js:35:21)\n    at Compilation.seal (./node_modules/webpack/lib/Compilation.js:914:27)\n    at hooks.make.callAsync.err (./node_modules/webpack/lib/Compiler.js:494:17)\n    at _err0 (eval at create (./node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:11:1)\n    at _addModuleChain (./node_modules/webpack/lib/Compilation.js:783:12)\n    at processModuleDependencies.err (./node_modules/webpack/lib/Compilation.js:722:9)\n    at process._tickCallback (internal/process/next_tick.js:61:11)\n @ ./src/index.js 1:0-21"
  ],
  "warnings": [
    "configuration\nThe 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment.\nYou can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/concepts/mode/"
  ],
  "version": "4.14.0",
  "hash": "ea6299e36625e28307d2",
  "time": 866,
  "builtAt": 1530528426430,
  "publicPath": "",
  "outputPath": "./dist",
  "assetsByChunkName": {
    "main": "main.js"
  },
  "assets": [
    {
      "name": "32634617ae3a4f18ec07bdf6e4903fe2.js",
      "size": 2260,
      "chunks": [],
      "chunkNames": []
    },
    {
      "name": "main.js",
      "size": 5561,
      "chunks": [
        0
      ],
      "chunkNames": [
        "main"
      ]
    }
  ],
  "filteredAssets": 0,
  "entrypoints": {
    "main": {
      "chunks": [
        0
      ],
      "assets": [
        "main.js"
      ],
      "children": {},
      "childAssets": {}
    }
  },
  "namedChunkGroups": {
    "main": {
      "chunks": [
        0
      ],
      "assets": [
        "main.js"
      ],
      "children": {},
      "childAssets": {}
    }
  },
  "chunks": [
    {
      "id": 0,
      "rendered": true,
      "initial": true,
      "entry": true,
      "size": 4611,
      "names": [
        "main"
      ],
      "files": [
        "main.js"
      ],
      "hash": "1be221368db4547a8529",
      "siblings": [],
      "parents": [],
      "children": [],
      "childrenByOrder": {},
      "modules": [
        {
          "id": 0,
          "identifier": "./node_modules/mini-css-extract-plugin/dist/loader.js!./node_modules/css-loader/index.js!./src/style.css",
          "name": "./src/style.css",
          "index": 1,
          "index2": 0,
          "size": 4590,
          "cacheable": true,
          "built": true,
          "optional": false,
          "prefetched": false,
          "chunks": [
            0
          ],
          "issuer": "./node_modules/babel-loader/lib/index.js!./src/index.js",
          "issuerId": 1,
          "issuerName": "./src/index.js",
          "issuerPath": [
            {
              "id": 1,
              "identifier": "./node_modules/babel-loader/lib/index.js!./src/index.js",
              "name": "./src/index.js"
            }
          ],
          "failed": true,
          "errors": 1,
          "warnings": 0,
          "assets": [],
          "reasons": [
            {
              "moduleId": 1,
              "moduleIdentifier": "./node_modules/babel-loader/lib/index.js!./src/index.js",
              "module": "./src/index.js",
              "moduleName": "./src/index.js",
              "type": "harmony side effect evaluation",
              "userRequest": "./style.css",
              "loc": "1:0-21"
            }
          ],
          "usedExports": false,
          "providedExports": null,
          "optimizationBailout": [
            "ModuleConcatenation bailout: Module is not an ECMAScript module"
          ],
          "depth": 1,
          "source": "throw new Error(\"Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):\\nTypeError: __webpack_require__(...) is not a function\\n    at Object.<anonymous> (./node_modules/css-loader/index.js!./src/style.css:98:50)\\n    at __webpack_require__ (./node_modules/css-loader/index.js!./src/style.css:21:30)\\n    at module.exports.module.exports (./node_modules/css-loader/index.js!./src/style.css:85:18)\\n    at Object.<anonymous> (./node_modules/css-loader/index.js!./src/style.css:88:10)\\n    at Module._compile (./node_modules/v8-compile-cache/v8-compile-cache.js:178:30)\\n    at exec (./node_modules/mini-css-extract-plugin/dist/loader.js:55:10)\\n    at childCompiler.runAsChild (./node_modules/mini-css-extract-plugin/dist/loader.js:133:14)\\n    at compile (./node_modules/webpack/lib/Compiler.js:243:11)\\n    at hooks.afterCompile.callAsync.err (./node_modules/webpack/lib/Compiler.js:500:14)\\n    at AsyncSeriesHook.eval [as callAsync] (eval at create (./node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:15:1)\\n    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (./node_modules/tapable/lib/Hook.js:35:21)\\n    at compilation.seal.err (./node_modules/webpack/lib/Compiler.js:497:30)\\n    at AsyncSeriesHook.eval [as callAsync] (eval at create (./node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:6:1)\\n    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (./node_modules/tapable/lib/Hook.js:35:21)\\n    at hooks.optimizeAssets.callAsync.err (./node_modules/webpack/lib/Compilation.js:995:35)\\n    at AsyncSeriesHook.eval [as callAsync] (eval at create (./node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:6:1)\\n    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (./node_modules/tapable/lib/Hook.js:35:21)\\n    at hooks.optimizeChunkAssets.callAsync.err (./node_modules/webpack/lib/Compilation.js:986:32)\\n    at _err0 (eval at create (./node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:11:1)\\n    at ./node_modules/uglifyjs-webpack-plugin/dist/index.js:282:11\\n    at _class.runTasks (./node_modules/uglifyjs-webpack-plugin/dist/uglify/index.js:63:9)\\n    at UglifyJsPlugin.optimizeFn (./node_modules/uglifyjs-webpack-plugin/dist/index.js:195:16)\\n    at AsyncSeriesHook.eval [as callAsync] (eval at create (./node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:7:1)\\n    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (./node_modules/tapable/lib/Hook.js:35:21)\\n    at hooks.additionalAssets.callAsync.err (./node_modules/webpack/lib/Compilation.js:981:36)\\n    at AsyncSeriesHook.eval [as callAsync] (eval at create (./node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:6:1)\\n    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (./node_modules/tapable/lib/Hook.js:35:21)\\n    at hooks.optimizeTree.callAsync.err (./node_modules/webpack/lib/Compilation.js:977:32)\\n    at AsyncSeriesHook.eval [as callAsync] (eval at create (./node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:6:1)\\n    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (./node_modules/tapable/lib/Hook.js:35:21)\\n    at Compilation.seal (./node_modules/webpack/lib/Compilation.js:914:27)\\n    at hooks.make.callAsync.err (./node_modules/webpack/lib/Compiler.js:494:17)\\n    at _err0 (eval at create (./node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:11:1)\\n    at _addModuleChain (./node_modules/webpack/lib/Compilation.js:783:12)\\n    at processModuleDependencies.err (./node_modules/webpack/lib/Compilation.js:722:9)\\n    at process._tickCallback (internal/process/next_tick.js:61:11)\");"
        },
        {
          "id": 1,
          "identifier": "./node_modules/babel-loader/lib/index.js!./src/index.js",
          "name": "./src/index.js",
          "index": 0,
          "index2": 1,
          "size": 21,
          "cacheable": true,
          "built": true,
          "optional": false,
          "prefetched": false,
          "chunks": [
            0
          ],
          "issuer": null,
          "issuerId": null,
          "issuerName": null,
          "issuerPath": null,
          "failed": false,
          "errors": 0,
          "warnings": 0,
          "assets": [],
          "reasons": [
            {
              "moduleId": null,
              "moduleIdentifier": null,
              "module": null,
              "moduleName": null,
              "type": "single entry",
              "userRequest": "./src",
              "loc": "main"
            }
          ],
          "usedExports": true,
          "providedExports": [],
          "optimizationBailout": [
            "ModuleConcatenation bailout: Module is an entry point"
          ],
          "depth": 0,
          "source": "import \"./style.css\";"
        }
      ],
      "filteredModules": 0,
      "origins": [
        {
          "module": "",
          "moduleIdentifier": "",
          "moduleName": "",
          "loc": "main",
          "request": "./src",
          "reasons": []
        }
      ]
    }
  ],
  "modules": [
    {
      "id": 0,
      "identifier": "./node_modules/mini-css-extract-plugin/dist/loader.js!./node_modules/css-loader/index.js!./src/style.css",
      "name": "./src/style.css",
      "index": 1,
      "index2": 0,
      "size": 4590,
      "cacheable": true,
      "built": true,
      "optional": false,
      "prefetched": false,
      "chunks": [
        0
      ],
      "issuer": "./node_modules/babel-loader/lib/index.js!./src/index.js",
      "issuerId": 1,
      "issuerName": "./src/index.js",
      "issuerPath": [
        {
          "id": 1,
          "identifier": "./node_modules/babel-loader/lib/index.js!./src/index.js",
          "name": "./src/index.js"
        }
      ],
      "failed": true,
      "errors": 1,
      "warnings": 0,
      "assets": [],
      "reasons": [
        {
          "moduleId": 1,
          "moduleIdentifier": "./node_modules/babel-loader/lib/index.js!./src/index.js",
          "module": "./src/index.js",
          "moduleName": "./src/index.js",
          "type": "harmony side effect evaluation",
          "userRequest": "./style.css",
          "loc": "1:0-21"
        }
      ],
      "usedExports": false,
      "providedExports": null,
      "optimizationBailout": [
        "ModuleConcatenation bailout: Module is not an ECMAScript module"
      ],
      "depth": 1,
      "source": "throw new Error(\"Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):\\nTypeError: __webpack_require__(...) is not a function\\n    at Object.<anonymous> (./node_modules/css-loader/index.js!./src/style.css:98:50)\\n    at __webpack_require__ (./node_modules/css-loader/index.js!./src/style.css:21:30)\\n    at module.exports.module.exports (./node_modules/css-loader/index.js!./src/style.css:85:18)\\n    at Object.<anonymous> (./node_modules/css-loader/index.js!./src/style.css:88:10)\\n    at Module._compile (./node_modules/v8-compile-cache/v8-compile-cache.js:178:30)\\n    at exec (./node_modules/mini-css-extract-plugin/dist/loader.js:55:10)\\n    at childCompiler.runAsChild (./node_modules/mini-css-extract-plugin/dist/loader.js:133:14)\\n    at compile (./node_modules/webpack/lib/Compiler.js:243:11)\\n    at hooks.afterCompile.callAsync.err (./node_modules/webpack/lib/Compiler.js:500:14)\\n    at AsyncSeriesHook.eval [as callAsync] (eval at create (./node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:15:1)\\n    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (./node_modules/tapable/lib/Hook.js:35:21)\\n    at compilation.seal.err (./node_modules/webpack/lib/Compiler.js:497:30)\\n    at AsyncSeriesHook.eval [as callAsync] (eval at create (./node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:6:1)\\n    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (./node_modules/tapable/lib/Hook.js:35:21)\\n    at hooks.optimizeAssets.callAsync.err (./node_modules/webpack/lib/Compilation.js:995:35)\\n    at AsyncSeriesHook.eval [as callAsync] (eval at create (./node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:6:1)\\n    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (./node_modules/tapable/lib/Hook.js:35:21)\\n    at hooks.optimizeChunkAssets.callAsync.err (./node_modules/webpack/lib/Compilation.js:986:32)\\n    at _err0 (eval at create (./node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:11:1)\\n    at ./node_modules/uglifyjs-webpack-plugin/dist/index.js:282:11\\n    at _class.runTasks (./node_modules/uglifyjs-webpack-plugin/dist/uglify/index.js:63:9)\\n    at UglifyJsPlugin.optimizeFn (./node_modules/uglifyjs-webpack-plugin/dist/index.js:195:16)\\n    at AsyncSeriesHook.eval [as callAsync] (eval at create (./node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:7:1)\\n    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (./node_modules/tapable/lib/Hook.js:35:21)\\n    at hooks.additionalAssets.callAsync.err (./node_modules/webpack/lib/Compilation.js:981:36)\\n    at AsyncSeriesHook.eval [as callAsync] (eval at create (./node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:6:1)\\n    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (./node_modules/tapable/lib/Hook.js:35:21)\\n    at hooks.optimizeTree.callAsync.err (./node_modules/webpack/lib/Compilation.js:977:32)\\n    at AsyncSeriesHook.eval [as callAsync] (eval at create (./node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:6:1)\\n    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (./node_modules/tapable/lib/Hook.js:35:21)\\n    at Compilation.seal (./node_modules/webpack/lib/Compilation.js:914:27)\\n    at hooks.make.callAsync.err (./node_modules/webpack/lib/Compiler.js:494:17)\\n    at _err0 (eval at create (./node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:11:1)\\n    at _addModuleChain (./node_modules/webpack/lib/Compilation.js:783:12)\\n    at processModuleDependencies.err (./node_modules/webpack/lib/Compilation.js:722:9)\\n    at process._tickCallback (internal/process/next_tick.js:61:11)\");"
    },
    {
      "id": 1,
      "identifier": "./node_modules/babel-loader/lib/index.js!./src/index.js",
      "name": "./src/index.js",
      "index": 0,
      "index2": 1,
      "size": 21,
      "cacheable": true,
      "built": true,
      "optional": false,
      "prefetched": false,
      "chunks": [
        0
      ],
      "issuer": null,
      "issuerId": null,
      "issuerName": null,
      "issuerPath": null,
      "failed": false,
      "errors": 0,
      "warnings": 0,
      "assets": [],
      "reasons": [
        {
          "moduleId": null,
          "moduleIdentifier": null,
          "module": null,
          "moduleName": null,
          "type": "single entry",
          "userRequest": "./src",
          "loc": "main"
        }
      ],
      "usedExports": true,
      "providedExports": [],
      "optimizationBailout": [
        "ModuleConcatenation bailout: Module is an entry point"
      ],
      "depth": 0,
      "source": "import \"./style.css\";"
    }
  ],
  "filteredModules": 0,
  "children": [
    {
      "errors": [],
      "warnings": [],
      "publicPath": "",
      "outputPath": "./dist",
      "assetsByChunkName": {},
      "assets": [
        {
          "name": "32634617ae3a4f18ec07bdf6e4903fe2.js",
          "size": 2260,
          "chunks": [],
          "chunkNames": []
        }
      ],
      "filteredAssets": 0,
      "entrypoints": {
        "mini-css-extract-plugin": {
          "chunks": [
            0
          ],
          "assets": [
            "*"
          ],
          "children": {},
          "childAssets": {}
        }
      },
      "namedChunkGroups": {
        "mini-css-extract-plugin": {
          "chunks": [
            0
          ],
          "assets": [
            "*"
          ],
          "children": {},
          "childAssets": {}
        }
      },
      "chunks": [
        {
          "id": 0,
          "rendered": true,
          "initial": true,
          "entry": true,
          "size": 265,
          "names": [
            "mini-css-extract-plugin"
          ],
          "files": [
            "*"
          ],
          "hash": "3716ea1b8286787cc45e",
          "siblings": [],
          "parents": [],
          "children": [],
          "childrenByOrder": {},
          "modules": [
            {
              "id": 0,
              "identifier": "./node_modules/file-loader/dist/cjs.js!./node_modules/css-loader/lib/css-base.js",
              "name": "./node_modules/css-loader/lib/css-base.js",
              "index": 1,
              "index2": 0,
              "size": 81,
              "cacheable": true,
              "built": true,
              "optional": false,
              "prefetched": false,
              "chunks": [
                0
              ],
              "issuer": "./node_modules/css-loader/index.js!./src/style.css",
              "issuerId": 1,
              "issuerName": "./node_modules/css-loader!./src/style.css",
              "issuerPath": [
                {
                  "id": 1,
                  "identifier": "./node_modules/css-loader/index.js!./src/style.css",
                  "name": "./node_modules/css-loader!./src/style.css"
                }
              ],
              "failed": false,
              "errors": 0,
              "warnings": 0,
              "assets": [
                "32634617ae3a4f18ec07bdf6e4903fe2.js"
              ],
              "reasons": [
                {
                  "moduleId": 1,
                  "moduleIdentifier": "./node_modules/css-loader/index.js!./src/style.css",
                  "module": "./node_modules/css-loader!./src/style.css",
                  "moduleName": "./node_modules/css-loader!./src/style.css",
                  "type": "cjs require",
                  "userRequest": "../node_modules/css-loader/lib/css-base.js",
                  "loc": "1:27-80"
                }
              ],
              "usedExports": true,
              "providedExports": null,
              "optimizationBailout": [
                "ModuleConcatenation bailout: Module is not an ECMAScript module"
              ],
              "depth": 1,
              "source": "module.exports = __webpack_public_path__ + \"32634617ae3a4f18ec07bdf6e4903fe2.js\";"
            },
            {
              "id": 1,
              "identifier": "./node_modules/css-loader/index.js!./src/style.css",
              "name": "./node_modules/css-loader!./src/style.css",
              "index": 0,
              "index2": 1,
              "size": 184,
              "cacheable": true,
              "built": true,
              "optional": false,
              "prefetched": false,
              "chunks": [
                0
              ],
              "issuer": null,
              "issuerId": null,
              "issuerName": null,
              "issuerPath": null,
              "failed": false,
              "errors": 0,
              "warnings": 0,
              "assets": [],
              "reasons": [
                {
                  "moduleId": null,
                  "moduleIdentifier": null,
                  "module": null,
                  "moduleName": null,
                  "type": "single entry",
                  "userRequest": "!!./node_modules/css-loader/index.js!./src/style.css",
                  "loc": "mini-css-extract-plugin"
                }
              ],
              "usedExports": true,
              "providedExports": null,
              "optimizationBailout": [
                "ModuleConcatenation bailout: Module is not an ECMAScript module"
              ],
              "depth": 0,
              "source": "exports = module.exports = require(\"../node_modules/css-loader/lib/css-base.js\")(false);\n// imports\n\n\n// module\nexports.push([module.id, \"body { color: hotpink }\\n\", \"\"]);\n\n// exports\n"
            }
          ],
          "filteredModules": 0,
          "origins": [
            {
              "module": "",
              "moduleIdentifier": "",
              "moduleName": "",
              "loc": "mini-css-extract-plugin",
              "request": "!!./node_modules/css-loader/index.js!./src/style.css",
              "reasons": []
            }
          ]
        }
      ],
      "modules": [
        {
          "id": 0,
          "identifier": "./node_modules/file-loader/dist/cjs.js!./node_modules/css-loader/lib/css-base.js",
          "name": "./node_modules/css-loader/lib/css-base.js",
          "index": 1,
          "index2": 0,
          "size": 81,
          "cacheable": true,
          "built": true,
          "optional": false,
          "prefetched": false,
          "chunks": [
            0
          ],
          "issuer": "./node_modules/css-loader/index.js!./src/style.css",
          "issuerId": 1,
          "issuerName": "./node_modules/css-loader!./src/style.css",
          "issuerPath": [
            {
              "id": 1,
              "identifier": "./node_modules/css-loader/index.js!./src/style.css",
              "name": "./node_modules/css-loader!./src/style.css"
            }
          ],
          "failed": false,
          "errors": 0,
          "warnings": 0,
          "assets": [
            "32634617ae3a4f18ec07bdf6e4903fe2.js"
          ],
          "reasons": [
            {
              "moduleId": 1,
              "moduleIdentifier": "./node_modules/css-loader/index.js!./src/style.css",
              "module": "./node_modules/css-loader!./src/style.css",
              "moduleName": "./node_modules/css-loader!./src/style.css",
              "type": "cjs require",
              "userRequest": "../node_modules/css-loader/lib/css-base.js",
              "loc": "1:27-80"
            }
          ],
          "usedExports": true,
          "providedExports": null,
          "optimizationBailout": [
            "ModuleConcatenation bailout: Module is not an ECMAScript module"
          ],
          "depth": 1,
          "source": "module.exports = __webpack_public_path__ + \"32634617ae3a4f18ec07bdf6e4903fe2.js\";"
        },
        {
          "id": 1,
          "identifier": "./node_modules/css-loader/index.js!./src/style.css",
          "name": "./node_modules/css-loader!./src/style.css",
          "index": 0,
          "index2": 1,
          "size": 184,
          "cacheable": true,
          "built": true,
          "optional": false,
          "prefetched": false,
          "chunks": [
            0
          ],
          "issuer": null,
          "issuerId": null,
          "issuerName": null,
          "issuerPath": null,
          "failed": false,
          "errors": 0,
          "warnings": 0,
          "assets": [],
          "reasons": [
            {
              "moduleId": null,
              "moduleIdentifier": null,
              "module": null,
              "moduleName": null,
              "type": "single entry",
              "userRequest": "!!./node_modules/css-loader/index.js!./src/style.css",
              "loc": "mini-css-extract-plugin"
            }
          ],
          "usedExports": true,
          "providedExports": null,
          "optimizationBailout": [
            "ModuleConcatenation bailout: Module is not an ECMAScript module"
          ],
          "depth": 0,
          "source": "exports = module.exports = require(\"../node_modules/css-loader/lib/css-base.js\")(false);\n// imports\n\n\n// module\nexports.push([module.id, \"body { color: hotpink }\\n\", \"\"]);\n\n// exports\n"
        }
      ],
      "filteredModules": 0,
      "children": [],
      "name": "mini-css-extract-plugin node_modules/css-loader/index.js!src/style.css"
    }
  ]
}

@sokra
Copy link
Member

sokra commented Jun 29, 2018

hmm... seem like some file is loaded with the file-loader which should not be loaded with it...

Do you have the stats output of the child compilation?

@pravdomil
Copy link
Author

pravdomil commented Jul 2, 2018

I have updated previous comment.

@sokra
Copy link
Member

sokra commented Jul 2, 2018

Your config loads all .js files that are in node_modules with the file-loader (because of the first rule). That's wrong.

Maybe add a rule like that { test: /\.js$/ } just before the fallback rule:

@pravdomil
Copy link
Author

pravdomil commented Jul 2, 2018

make sense, now it works, that solves problem for me, thanks for help, final config:

const MiniCssExtractPlugin = require("mini-css-extract-plugin");

module.exports = {
  module: {
    rules: [
      {
        oneOf: [
          {
            test: /\.js$/,
            exclude: /node_modules/,
            loader: "babel-loader"
          },
          {
            test: /\.css$/,
            use: ["mini-css-extract-plugin/dist/loader.js", "css-loader"]
          },
          {
            exclude: /\.(js|mjs|json|wasm)$/,
            use: "file-loader"
          }
        ]
      }
    ]
  },
  plugins: [new MiniCssExtractPlugin()]
};

Webpack block

@webpack-bot
Copy link
Contributor

This issue had no activity for at least half a year.

It's subject to automatic issue closing if there is no activity in the next 15 days.

@alexander-akait
Copy link
Member

Bump

@webpack-bot
Copy link
Contributor

This issue had no activity for at least half a year.

It's subject to automatic issue closing if there is no activity in the next 15 days.

@alexander-akait
Copy link
Member

Bump, maybe we can do this for webpack@5
/cc @sokra

@terrylinooo
Copy link

I don't why exclude: /node_modules/, but it solved my problem.

@webpack-bot
Copy link
Contributor

This issue had no activity for at least three months.

It's subject to automatic issue closing if there is no activity in the next 15 days.

@edmorley
Copy link
Contributor

Unstale

@alexander-akait
Copy link
Member

bump

@webpack-bot
Copy link
Contributor

Issue was closed because of inactivity.

If you think this is still a valid issue, please file a new issue with additional information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants