jaydenseric / webpack-watch-server

A single npm script command to start Webpack and your server in watch mode, with a unified console.
https://npm.im/webpack-watch-server
9 stars 10 forks source link

"Error: Cannot find module xxx" while it seems to be working fine #5

Open TitoVince35 opened 6 years ago

TitoVince35 commented 6 years ago

Hello, Everything seems to be working OK, but I get this error at every build/start:

 module.js:557
     throw err;
    ^
 Error: Cannot find module '/usr/src/app/dist'
     at Function.Module._resolveFilename (module.js:555:15)
     at Function.Module._load (module.js:482:25)
     at Function.Module.runMain (module.js:701:10)
     at startup (bootstrap_node.js:190:16)
    at bootstrap_node.js:662:3

Here is my package.json

"scripts": {
    "dev": "webpack-watch-server --config webpack.dev.xeapi.js"
  },
(...)
  "devDependencies": {
    "babel-loader": "^7.1.4",
    "config-webpack": "^1.0.4",
    "eslint": "^4.19.0",
    "grunt": "^1.0.2",
    "grunt-contrib-clean": "^1.1.0",
    "grunt-env": "^0.4.4",
    "grunt-shell": "^2.1.0",
    "json-loader": "^0.5.7",
    "mocha": "^4.0.1",
    "request": "^2.85.0",
    "request-promise": "^4.2.2",
    "start-server-webpack-plugin": "^2.2.5",
    "webpack": "^4.5.0",
    "webpack-bundle-analyzer": "^2.11.1",
    "webpack-cli": "^2.0.14",
    "webpack-merge": "^4.1.2",
    "webpack-node-externals": "^1.7.2",
    "webpack-watch-server": "^1.2.1"
  }
(...)

Here is webpack.dev.xeapi.js

var path = require('path');
var webpack = require('webpack');
const merge = require('webpack-merge');
const common = require('./webpack.common.xeapi.js');
module.exports = merge(common, {
    mode : 'development',
    cache : true,
    stats: {
        // Nice colored output
        colors: true
    },
    // Create Sourcemaps for the bundle
    devtool: 'inline-source-map'
});

...and the required webpack.common.xeapi.js

const path = require('path');
const webpack = require('webpack');
const nodeExternals = require('webpack-node-externals');

module.exports = {
    entry: {
    main: ['./src/index.js']
    },
    output: {
        path: path.join(__dirname,'dist/'),
        filename: 'server-app.js'
    },
    module: {
        rules: [
          {
            test: /\.js$/,
            use: [{
              loader: 'babel-loader',
              options: { presets: ['es2015'] }
            }],
          },
        ],
      },
  // Keep node_modules out of the generated bundle
  target: 'node',
  externals: [nodeExternals()],
};

Does that ring a bell?

Thanks in advance,

Vince

jaydenseric commented 6 years ago

While I still believe the approach of this package is the best for a server compiled with Webpack, I simply don't use it anymore because I no longer use Webpack for the server. Running native ESM using node --experimental-modules via .mjs is great! With the latest versions of Node.js you don't really need to transpile anything anymore. I use Next.js for clients, which handles watching.

Since I stopped using this package the dependencies have gotten a little out of date. For example, Webpack v4 (which you are using) has not been tested and added to the peer dependency version range.

Nothing jumps out glancing over your setup, but then I could be missing something obvious, sorry!

TitoVince35 commented 6 years ago

Ok, thanks for the quick answer. I'm just trying to lift up a bit my company's legacy technical stack, but we're not there yet. I understand it's quite a challenge to keep up with the dependencies' fast upgrade, since you no longer rely on this package. Nevermind, it's more like a warning than an actual error, anyway. Have a nice day.