Skip to content
This repository has been archived by the owner on Sep 9, 2021. It is now read-only.

Cannot resolve node.js core modules in Webpack 2 #55

Closed
GProst opened this issue Mar 18, 2017 · 15 comments
Closed

Cannot resolve node.js core modules in Webpack 2 #55

GProst opened this issue Mar 18, 2017 · 15 comments

Comments

@GProst
Copy link

GProst commented Mar 18, 2017

After I migrated from webpack 1 it started to throw following errors:

Module not found: Error: Can't resolve 'path' in /absolute-file-path

Modules, which cause errors are: path, fs, vm, crypto and constants

I've figured out that webpack can't resolve it only when it required from file, which was processed by worker-loader.

Tried to load it via require(worker-loader!file-name.js) syntax and via webpack.config.js settings

Here is my webpack.config.js:

const config = {
  target: 'electron-renderer',
  context: __dirname,
  entry: { app: './app.js', vendor: [/*vendors*/]},
  cache: true,
  devtool: 'source-map',
  watch: false

  resolve: {
    extensions: ['.js', '.json', '.jsx'],
    modules: ["node_modules"]
  },

  module: {

    rules: [
      {test: /\.html/, loader: 'html-loader'},
      {test: /worker\.js/, loader: 'worker-loader'},
      {
        test: /\.less$/,
        use: ExtractTextPlugin.extract({
          fallback: "style-loader",
          use: ["css-loader?sourceMap", "less-loader?sourceMap"]
        })
      },
      {
        test: /\.css/,
        use: ExtractTextPlugin.extract({
          fallback: "style-loader",
          use: "css-loader?sourceMap"
        })
      },
      {test: /\.(jpg|png|gif|jpeg|svg|otf|ttf|eot|woff)$/, loader: 'url-loader?limit=10000'}
    ]
  },

  plugins: [

    new ExtractTextPlugin('styles.[contenthash].css'),

    new webpack.optimize.CommonsChunkPlugin({
      names: ['commons', 'vendor', 'manifest'],
      minChuncks: Infinity
    }),

    new HtmlWebpackPlugin({
      template: './index.html',
      filename: 'index.html',
      hash: false,
      inject: 'head',
      cashe: true,
      showErrors: true
    })

  ],

  output: {
    publicPath: './',
    path: path.join(__dirname, 'dist'),
    filename: '[name].[chunkhash].js',
    chunkFilename: '[name].[chunkhash].js'
  }
};

module.exports = config;
@GProst
Copy link
Author

GProst commented Mar 18, 2017

I thought it could be because of nvm which I use, but I switched to system nodejs via nvm use system command and webpack still throws these errors.

I also thought it could be target property, so I changed it to node, but it didn't help too.

@GProst
Copy link
Author

GProst commented Mar 18, 2017

It looks like it referenced to #44

@TrySound
Copy link
Contributor

@GProst Does it still work with webpack 1

@GProst
Copy link
Author

GProst commented Mar 19, 2017

@TrySound all worked well when I was on webpack 1, if that's what you asked

@TrySound
Copy link
Contributor

I mean current version of worker loader with webpack 1.

@GProst
Copy link
Author

GProst commented Mar 20, 2017

@TrySound yep, I've just checked it. 0.8.0 version seems to work fine with webpack 1. Btw, I updated up all of my loaders when migrated.

@ghost
Copy link

ghost commented Apr 5, 2017

Hi,

I ran into the same problem today. Any progress on this one so far?

@TrySound
Copy link
Contributor

TrySound commented Apr 5, 2017

@mdh-cc Not yet. I will be glad to accept a PR.

@Zuzon
Copy link

Zuzon commented May 13, 2017

any news?

@alexander-akait
Copy link
Member

@Zuzon can your create minimal reproducible test repo?

@Zuzon
Copy link

Zuzon commented May 13, 2017

in my case:
webpack build target is 'node-webkit' and when i try to import 'path' module in worker

@avarayr
Copy link

avarayr commented May 22, 2017

If anyone runs into this problem like me (being a complete beginner) using electron and WebWorkers, the issue is that web workers don't support Node so it is not possible to use fs or path

@Zuzon
Copy link

Zuzon commented May 24, 2017

it's possible with nwjs since 0.18.4

@FrogTheFrog
Copy link
Contributor

Any news regarding this issue?

@ahutchings
Copy link

Can this be closed since #76 was merged and included in 1.0.0?

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

No branches or pull requests

8 participants