speed-measure-webpack-plugin icon indicating copy to clipboard operation
speed-measure-webpack-plugin copied to clipboard

Error: ENOENT: no such file or directory, lstat '/index.js'

Open joepio opened this issue 4 years ago • 2 comments

Hi there!

In one of my projects, I can't get SMP to load. Note that the error appears even if I don't call smp.wrap.

I keep getting this:

Error: ENOENT: no such file or directory, lstat '/index.js'
    at Object.realpathSync (fs.js:1476:7)
    at Object.<anonymous> (/home/joep/dev/src/bitbucket.org/arguweb/aod_demo/dist/private/server.js:433889:28)
    at Object../node_modules/speed-measure-webpack-plugin/index.js (/home/joep/dev/src/bitbucket.org/arguweb/aod_demo/dist/private/server.js:434066:30)
    at __webpack_require__ (/home/joep/dev/src/bitbucket.org/arguweb/aod_demo/dist/private/server.js:21:30)
    at Object../webpack/hot.config.js (/home/joep/dev/src/bitbucket.org/arguweb/aod_demo/dist/private/server.js:442544:28)
    at __webpack_require__ (/home/joep/dev/src/bitbucket.org/arguweb/aod_demo/dist/private/server.js:21:30)
    at Object../server/middleware/devMiddleware.js (/home/joep/dev/src/bitbucket.org/arguweb/aod_demo/dist/private/server.js:440016:35)
    at __webpack_require__ (/home/joep/dev/src/bitbucket.org/arguweb/aod_demo/dist/private/server.js:21:30)
    at module.exports../server/server.js.Promise.resolve.then (/home/joep/dev/src/bitbucket.org/arguweb/aod_demo/dist/private/server.js:440844:70)
    at processTicksAndRejections (internal/process/task_queues.js:86:5)

I'm not sure which /index.js the error means. I assume it's the index of SMP, but the ./node_modules/speed-measure-webpack-plugin/index.js file exists.

In the compiled server.js file, this line causes the error:

/* WEBPACK VAR INJECTION */}.call(this, "/index.js"))

Here's my webpack config:

// hot.config.js
const SpeedMeasurePlugin = require('speed-measure-webpack-plugin');
const webpack = require('webpack');
const merge = require('webpack-merge');
const WebpackPwaManifest = require('webpack-pwa-manifest');

const common = require('./common.config');
const manifest = require('./manifest.json');

module.exports = merge.smart(common, {
  cache: true,

  devtool: 'cheap-eval-source-map',

  entry: [
    'webpack-hot-middleware/client',
    './app/index.jsx',
  ],

  mode: 'development',

  module: {
    rules: [
      {
        exclude: /node_modules/,
        test: /\.(m?(t|j)sx?)$/,
        use: ['babel-loader'],
      },
      {
        test: /\.(sa|sc|c)ss$/,
        use: [
          {
            loader: 'style-loader',
            options: { sourceMap: true },
          },
          {
            loader: 'css-loader',
            options: { sourceMap: true },
          },
          {
            loader: 'postcss-loader',
            options: { sourceMap: true },
          },
          {
            loader: 'sass-loader',
            options: { sourceMap: true },
          },
        ],
      },
    ],
  },

  output: {
    globalObject: "(typeof self !== 'undefined' ? self : this)",
    pathinfo: true,
    publicPath: '/',
  },

  plugins: [
    new webpack.DefinePlugin({
      __LEGACY__: false,
      'process.env.FRONTEND_HOSTNAME': JSON.stringify(process.env.FRONTEND_HOSTNAME),
    }),
    new webpack.HotModuleReplacementPlugin(),
    new WebpackPwaManifest({
      ...manifest,
      filename: 'manifest.json',
    }),
    new webpack.NoEmitOnErrorsPlugin(),
  ],

  resolve: {
    alias: {
      'react-dom': '@hot-loader/react-dom',
    },
  },
});

And my common.config:

const path = require('path');

const CompressionPlugin = require('compression-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const WorkboxPlugin = require('workbox-webpack-plugin');

const version = require('./version');

const TARGET = process.env.npm_lifecycle_event;
process.env.BABEL_ENV = TARGET;

const common = {
  externals: {
    URL: 'self.URL',
  },

  mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',

  module: {
    rules: [
      {
        test: /\.png$/,
        use: 'file-loader?name=[name].[ext]',
      }, {
        test: /\.jpg$/,
        use: 'file-loader?name=[name].[ext]',
      },
    ],
  },

  output: {
    filename: '[name].bundle.js',
    path: path.resolve(__dirname, '..', 'dist', 'public'),
  },

  plugins: [
    new CleanWebpackPlugin(),
    new CopyWebpackPlugin([
      {
        from: 'static/preloader.css',
        to: path.resolve(__dirname, '..', 'dist', 'public'),
      },
    ]),
    new webpack.ProvidePlugin({
      xmlhttprequest: 'imports-loader?this=>global!exports-loader?global.XMLHttpRequest!global.XMLHttpRequest',
    }),
    new webpack.DefinePlugin({
      __CLIENT__: true,
      __DEVELOPMENT__: process.env.NODE_ENV === 'development',
      __ORIGIN__: JSON.stringify(`https://${process.env.FRONTEND_HOSTNAME}`),
      __PRODUCTION__: process.env.NODE_ENV === 'production',
      __TEST__: process.env.NODE_ENV === 'test',
      __VERSION__: JSON.stringify(version),
      'process.env': {
        NODE_ENV: process.env.NODE_ENV === 'development' ? '"development"' : '"production"',
      },
    }),
    new webpack.optimize.ModuleConcatenationPlugin(),
    new HtmlWebpackPlugin({
      filename: 'public/offline.html',
      template: 'app/offline.html',
    }),
    new WorkboxPlugin.InjectManifest({
      // importWorkboxFrom: 'disabled',
      // importsDirectory: 'workbench',
      swDest: './public/sw.js',
      swSrc: './app/sw.js',
    }),
    new CompressionPlugin({
      algorithm: 'gzip',
      filename: '[path].gz[query]',
      minRatio: 1,
      test: /\.js$|\.css$|\.html$/,
      threshold: 0,
    }),
  ],

  resolve: {
    alias: {
      react: path.resolve('node_modules/react'),
      static: path.resolve('./static'),
    },
    extensions: ['.js', '.jsx', '.mjs', '.ts', '.tsx'],
    modules: ['./node_modules'],
  },
};

module.exports = common;

I tried reinstalling, removing node_modules, wrapping the config in smp.wrap, tried some different versions of SMP. I'm running node v11.15.0, webpack 4.39.2.

Thanks in advance!

joepio avatar Aug 27 '19 09:08 joepio

Just to make sure I understand, the error appears specifically on the require statement alone?

stephencookdev avatar Sep 03 '19 08:09 stephencookdev

Yes, it appears before any funcitons are called - the mere import (require statement) causes the error.

joepio avatar Sep 03 '19 08:09 joepio