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

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

Open
joepio opened this issue Aug 27, 2019 · 2 comments
Open

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

joepio opened this issue Aug 27, 2019 · 2 comments

Comments

@joepio
Copy link

joepio commented Aug 27, 2019

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!

@stephencookdev
Copy link
Owner

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

@joepio
Copy link
Author

joepio commented Sep 3, 2019

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

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