webpack-cli: [BUG]: ERROR in main: Can't resolve `./src`

Describe the bug I have the following project folder structure:

my-app/
├─ .webpack/
│  ├─ index.js
│  ├─ development.js
│  ├─ production.js
├─ node_modules/
├─ src/
│  ├─ index.tsx
├─ package.json

When I use .webpack/index.js to import a specific environment configuration I get the following error:

ERROR in main
Module not found: Error: Can't resolve './src' in '/Users/<path-to-project>/my-app'

To Reproduce

package.json

"@webpack-cli/serve": "^1.0.1-rc.0",
"webpack": "^5.0.0-rc.0",
"webpack-cli": "^4.0.0-rc.0",
"webpack-dev-server": "^3.11.0"

.webpack/index.js

module.exports = (env, arg) => {
  const { mode } = arg;
  const config = require(`./${mode}`);

  return config;
};

.webpack/development.js

module.exports = {
  entry:  path.resolve(__dirname, '../src/index.tsx'),
  output: {
    path: path.resolve(__dirname, '../build/'),
    filename: 'index.js'
  },
  devtool: 'source-map',
  devServer: {
    inline: true,
    port: 8080,
    contentBase: path.resolve(__dirname, '../src')
  },
  module: {
      rules: [
          { test: /\.tsx?$/, loader: 'awesome-typescript-loader' }
      ]
  },
  resolve: {
    modules: [
      '/Users/<path-to-project>/my-app/src',
      'node_modules'
    ],
    extensions: ['.wasm', '.mjs', '.js', '.jsx', '.ts', '.tsx', '.json'],
  }
};
> webpack serve --config .webpack/index.js --mode development

Expected behavior

Expected the src directory to be resolved. If instead .webpack/index.js has the configuration there is no error that shows up.

Please paste the results of webpack-cli info here, and mention other relevant information

System:
    OS: macOS 10.15.6
    CPU: (8) x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
    Memory: 451.53 MB / 16.00 GB
  Binaries:
    Node: 14.5.0 - ~/.nvm/versions/node/v14.5.0/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.8 - ~/.nvm/versions/node/v14.5.0/bin/npm
  Browsers:
    Firefox: 81.0
    Safari: 14.0
  Packages:
    case-sensitive-paths-webpack-plugin: ^2.3.0 => 2.3.0
    clean-webpack-plugin: ^3.0.0 => 3.0.0
    extract-css-chunks-webpack-plugin: ^4.7.5 => 4.7.5
    html-webpack-plugin: ^4.5.0 => 4.5.0
    webpack: ^5.0.0-rc.0 => 5.0.0-rc.0
    webpack-cli: ^4.0.0-rc.0 => 4.0.0-rc.0
    webpack-dev-server: ^3.11.0 => 3.11.0
    webpack-merge: ^5.1.4 => 5.1.4

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 29 (15 by maintainers)

Most upvoted comments

@bahtou we will do new rc release in Monday, so you will need just update 😄

EDIT: https://github.com/webpack/webpack-cli/pull/1837/ should fix this, @snitin315 can you check once I push?

I’ll fix CI today

@bahtou you don’t need @webpack-cli/serve

@gairTanm no

@bahtou it’s webpack core, the issue was in CLI (this repo). Hence once CLI RC is released this should be fixed.

Have a look at this to reproduce the issue: https://github.com/bahtou/webpack-server-issue/tree/master

Thanks for reporting I’m looking into it.

can you once try if the following is working ? -

​>​ webpack serve --config .webpack/index.js --mode development --entry src/index.tsx

Sure, feel free to PR. I don’t think that will be enough since we’re just adding another property on the object before assigning it again. You can start with creating a test which will fail now and debug and fix it.

@bahtou I think you’ll have to install the webpack-cli bleeding edge. The issue, if I understand it correctly, was with webpack-cli. Nevertheless, I think it will be better to wait for the rc release on Monday.

> webpack serve --config .webpack/index.js --mode development --entry src/index.tsx

[webpack-cli]
Error: you provided an invalid entry point.

[webpack-cli] ValidationError: Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
 - configuration.entry should be an non-empty array.
   -> All modules are loaded upon startup. The last one is exported.

[webpack-cli] Promise rejection: TypeError: Cannot read property 'compilers' of undefined
[webpack-cli] TypeError: Cannot read property 'compilers' of undefined
    at Object.getDevServerOptions [as default] (/Users/<path-to-project>/my-app/node_modules/@webpack-cli/serve/lib/getDevServerOptions.js:15:32)
    at Object.startDevServer [as default] (/Users/<path-to-project>/my-app/node_modules/@webpack-cli/serve/lib/startDevServer.js:22:59)
    at /Users/<path-to-project>/my-app/node_modules/@webpack-cli/serve/lib/index.js:21:33