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

webpack serve errors out, saying it can't find 7 files. #3221

Closed
1 task
alex-ironside opened this issue Apr 23, 2021 · 1 comment
Closed
1 task

webpack serve errors out, saying it can't find 7 files. #3221

alex-ironside opened this issue Apr 23, 2021 · 1 comment

Comments

@alex-ironside
Copy link

alex-ironside commented Apr 23, 2021

  • Operating System: Ubuntu 20.04.2 LTS
  • Node Version: 14.15.4
  • NPM Version: 6.14.10
  • webpack Version: 5.35.1
  • webpack-dev-server Version: 3.11.2
  • Browser: Mozilla Firefox 87.0 (not related)
  • [x ] This is a bug
  • This is a modification request

Code

webpack.common.js

const path = require("path");

module.exports = {
  entry: {
    index: "./src/scripts/index.ts",
    library: "./src/scripts/library.ts",
  },
  resolve: {
    extensions: [".ts"],
  },
  module: {
    rules: [
      {
        test: /\.ts?$/,
        use: "ts-loader",
        exclude: /node_modules/,
      },
      {
        test: /\.html$/i,
        loader: "html-loader",
      },
    ],
  },
};

webpack.dev.js

const path = require("path");
const common = require("./webpack.common.js");
const { merge } = require("webpack-merge");
const HtmlWebpackPlugin = require("html-webpack-plugin");

module.exports = merge(common, {
  output: {
    filename: "[name].bundle.js",
    path: path.resolve(__dirname, "dev"),
  },
  module: {
    rules: [
      {
        test: /\.scss$/i,
        use: ["style-loader", "css-loader", "sass-loader"],
      },
    ],
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: "./src/index.html",
    }),
  ],
  mode: "development",
  devServer: { // problem here
    contentBase: path.join(__dirname, "dev"),
    compress: true,
    port: 9000,
  },
});
{
  "name": "webpack-example",
  "version": "1.0.0",
  "description": "",
  "private": "true",
  "scripts": {
    "dev": "npx webpack serve --config webpack.dev.js",
    "build": "npx webpack --config webpack.prod.js"
  },
  "repository": {
    "type": "git",
    "url": "git+ssh://git@gitlab.com/iron.alex/webpack-example.git"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "clean-webpack-plugin": "^4.0.0-alpha.0",
    "css-loader": "^5.2.4",
    "html-loader": "^2.1.2",
    "html-webpack-plugin": "^5.3.1",
    "mini-css-extract-plugin": "^1.5.0",
    "node-sass": "^5.0.0",
    "sass": "^1.32.11",
    "sass-loader": "^11.0.1",
    "style-loader": "^2.0.0",
    "ts-loader": "^9.1.0",
    "typescript": "^4.2.4",
    "webpack": "^5.35.1",
    "webpack-cli": "^4.6.0",
    "webpack-dev-server": "^3.11.2",
    "webpack-merge": "^5.7.3"
  }
}

Expected Behavior - I was expecting the dev server to start.

Actual Behavior - Dev server failed to start, throwing errors

ERROR in ./node_modules/webpack-dev-server/client/index.js?http://localhost:9000 6:16-37
Module not found: Error: Can't resolve 'strip-ansi' in '/home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client'
resolve 'strip-ansi' in '/home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client'
  Parsed request is a module
  using description file: /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/package.json (relative path: ./client)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client/node_modules doesn't exist or is not a directory
      looking for modules in /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/node_modules
        single file module
          using description file: /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/package.json (relative path: ./node_modules/strip-ansi)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/node_modules/strip-ansi doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/node_modules/strip-ansi.ts doesn't exist
        /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/node_modules/strip-ansi doesn't exist
      /home/aironside/Documents/private/webpack-example/node_modules/node_modules doesn't exist or is not a directory
      looking for modules in /home/aironside/Documents/private/webpack-example/node_modules
        single file module
          using description file: /home/aironside/Documents/private/webpack-example/package.json (relative path: ./node_modules/strip-ansi)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /home/aironside/Documents/private/webpack-example/node_modules/strip-ansi is not a file
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              /home/aironside/Documents/private/webpack-example/node_modules/strip-ansi.ts doesn't exist
        existing directory /home/aironside/Documents/private/webpack-example/node_modules/strip-ansi
          using description file: /home/aironside/Documents/private/webpack-example/node_modules/strip-ansi/package.json (relative path: .)
            using description file: /home/aironside/Documents/private/webpack-example/package.json (relative path: ./node_modules/strip-ansi)
              no extension
                Field 'browser' doesn't contain a valid alias configuration
                /home/aironside/Documents/private/webpack-example/node_modules/strip-ansi is not a file
              .ts
                Field 'browser' doesn't contain a valid alias configuration
                /home/aironside/Documents/private/webpack-example/node_modules/strip-ansi.ts doesn't exist
              as directory
                existing directory /home/aironside/Documents/private/webpack-example/node_modules/strip-ansi
                  using description file: /home/aironside/Documents/private/webpack-example/node_modules/strip-ansi/package.json (relative path: .)
                    using path: /home/aironside/Documents/private/webpack-example/node_modules/strip-ansi/index
                      using description file: /home/aironside/Documents/private/webpack-example/node_modules/strip-ansi/package.json (relative path: ./index)
                        no extension
                          Field 'browser' doesn't contain a valid alias configuration
                          /home/aironside/Documents/private/webpack-example/node_modules/strip-ansi/index doesn't exist
                        .ts
                          Field 'browser' doesn't contain a valid alias configuration
                          /home/aironside/Documents/private/webpack-example/node_modules/strip-ansi/index.ts doesn't exist
      /home/aironside/Documents/private/node_modules doesn't exist or is not a directory
      /home/aironside/Documents/node_modules doesn't exist or is not a directory
      /home/aironside/node_modules doesn't exist or is not a directory
      /home/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory

ERROR in ./node_modules/webpack-dev-server/client/index.js?http://localhost:9000 8:13-32
Module not found: Error: Can't resolve './socket' in '/home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client'
resolve './socket' in '/home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client'
  using description file: /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/package.json (relative path: ./client)
    Field 'browser' doesn't contain a valid alias configuration
    using description file: /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/package.json (relative path: ./client/socket)
      no extension
        Field 'browser' doesn't contain a valid alias configuration
        /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client/socket doesn't exist
      .ts
        Field 'browser' doesn't contain a valid alias configuration
        /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client/socket.ts doesn't exist
      as directory
        /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client/socket doesn't exist

ERROR in ./node_modules/webpack-dev-server/client/index.js?http://localhost:9000 10:14-34
Module not found: Error: Can't resolve './overlay' in '/home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client'
resolve './overlay' in '/home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client'
  using description file: /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/package.json (relative path: ./client)
    Field 'browser' doesn't contain a valid alias configuration
    using description file: /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/package.json (relative path: ./client/overlay)
      no extension
        Field 'browser' doesn't contain a valid alias configuration
        /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client/overlay doesn't exist
      .ts
        Field 'browser' doesn't contain a valid alias configuration
        /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client/overlay.ts doesn't exist
      as directory
        /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client/overlay doesn't exist

ERROR in ./node_modules/webpack-dev-server/client/index.js?http://localhost:9000 12:15-37
Module not found: Error: Can't resolve './utils/log' in '/home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client'
resolve './utils/log' in '/home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client'
  using description file: /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/package.json (relative path: ./client)
    Field 'browser' doesn't contain a valid alias configuration
    using description file: /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/package.json (relative path: ./client/utils/log)
      no extension
        Field 'browser' doesn't contain a valid alias configuration
        /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client/utils/log doesn't exist
      .ts
        Field 'browser' doesn't contain a valid alias configuration
        /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client/utils/log.ts doesn't exist
      as directory
        /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client/utils/log doesn't exist

ERROR in ./node_modules/webpack-dev-server/client/index.js?http://localhost:9000 16:18-48
Module not found: Error: Can't resolve './utils/sendMessage' in '/home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client'
resolve './utils/sendMessage' in '/home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client'
  using description file: /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/package.json (relative path: ./client)
    Field 'browser' doesn't contain a valid alias configuration
    using description file: /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/package.json (relative path: ./client/utils/sendMessage)
      no extension
        Field 'browser' doesn't contain a valid alias configuration
        /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client/utils/sendMessage doesn't exist
      .ts
        Field 'browser' doesn't contain a valid alias configuration
        /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client/utils/sendMessage.ts doesn't exist
      as directory
        /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client/utils/sendMessage doesn't exist

ERROR in ./node_modules/webpack-dev-server/client/index.js?http://localhost:9000 18:16-44
Module not found: Error: Can't resolve './utils/reloadApp' in '/home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client'
resolve './utils/reloadApp' in '/home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client'
  using description file: /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/package.json (relative path: ./client)
    Field 'browser' doesn't contain a valid alias configuration
    using description file: /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/package.json (relative path: ./client/utils/reloadApp)
      no extension
        Field 'browser' doesn't contain a valid alias configuration
        /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client/utils/reloadApp doesn't exist
      .ts
        Field 'browser' doesn't contain a valid alias configuration
        /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client/utils/reloadApp.ts doesn't exist
      as directory
        /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client/utils/reloadApp doesn't exist

ERROR in ./node_modules/webpack-dev-server/client/index.js?http://localhost:9000 20:22-56
Module not found: Error: Can't resolve './utils/createSocketUrl' in '/home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client'
resolve './utils/createSocketUrl' in '/home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client'
  using description file: /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/package.json (relative path: ./client)
    Field 'browser' doesn't contain a valid alias configuration
    using description file: /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/package.json (relative path: ./client/utils/createSocketUrl)
      no extension
        Field 'browser' doesn't contain a valid alias configuration
        /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client/utils/createSocketUrl doesn't exist
      .ts
        Field 'browser' doesn't contain a valid alias configuration
        /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client/utils/createSocketUrl.ts doesn't exist
      as directory
        /home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client/utils/createSocketUrl doesn't exist

webpack 5.35.1 compiled with 7 errors in 1754 ms

More readable error:


ERROR in ./node_modules/webpack-dev-server/client/index.js?http://localhost:9000 6:16-37
Module not found: Error: Can't resolve 'strip-ansi' in '/home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client'

ERROR in ./node_modules/webpack-dev-server/client/index.js?http://localhost:9000 8:13-32
Module not found: Error: Can't resolve './socket' in '/home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client'

ERROR in ./node_modules/webpack-dev-server/client/index.js?http://localhost:9000 10:14-34
Module not found: Error: Can't resolve './overlay' in '/home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client'

ERROR in ./node_modules/webpack-dev-server/client/index.js?http://localhost:9000 12:15-37
Module not found: Error: Can't resolve './utils/log' in '/home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client'

ERROR in ./node_modules/webpack-dev-server/client/index.js?http://localhost:9000 16:18-48
Module not found: Error: Can't resolve './utils/sendMessage' in '/home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client'

ERROR in ./node_modules/webpack-dev-server/client/index.js?http://localhost:9000 18:16-44
Module not found: Error: Can't resolve './utils/reloadApp' in '/home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client'

ERROR in ./node_modules/webpack-dev-server/client/index.js?http://localhost:9000 20:22-56
Module not found: Error: Can't resolve './utils/createSocketUrl' in '/home/aironside/Documents/private/webpack-example/node_modules/webpack-dev-server/client'

For Bugs; How can we reproduce the behavior? - Pull from this repo: https://gitlab.com/iron.alex/webpack-example

Webpack builds if I omit serve, so serve must be the issue. Or am I missing something?

@alexander-akait
Copy link
Member

This problem due this:

  resolve: {
    extensions: [".ts"],
  },

You disable js extensions, do not remove default values, please use ['ts', 'tsx', '...'], even more your can break a lot of other cases and break your app

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

No branches or pull requests

2 participants