KaiHotz / react-rollup-boilerplate

Boilerplate for creating React component libraries, bundled with Rollup.js to ESM and/or CJS Modules, Storybook, Typescript
https://kaihotz.github.io/react-rollup-boilerplate/
MIT License
300 stars 67 forks source link

ReferenceError: process is not defined #16

Closed Deep-Codes closed 3 years ago

Deep-Codes commented 3 years ago

Hey Fantastic Boilerplate, I had an issue which I solved I will place it here so that People can Solve it if they get Stuck.

Steps to Reproduce:

git clone git@github.com:KaiHotz/react-rollup-boilerplate.git
cd react-rollup-boilerplate
npm install or yarn
yarn start

Error Message at http://localhost:6060/

Screenshot 2021-02-16 at 7 23 12 PM

FIX for this:

yarn add -D process

Add Process Plugin to webpack.config.js

  plugins: [
    new webpack.ProvidePlugin({
      process: 'process/browser',
    }),
  ],

So complete webpack.config.js file:

// Webpack configuration
const webpack = require('webpack');

module.exports = {
  module: {
    rules: [
      { test: /\.tsx?$/, loader: 'ts-loader' },
      { enforce: 'pre', test: /\.js$/, loader: 'source-map-loader' },
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        use: ['babel-loader'],
      },
      {
        test: /\.(s?)css$/,
        use: ['style-loader', 'css-loader', 'sass-loader'],
      },
      {
        test: /\.(png|jpg|jpeg|webp|gif)$/,
        use: ['url-loader'],
      },
      {
        test: /\.svg$/,
        use: [
          {
            loader: '@svgr/webpack',
          },
        ],
      },
    ],
  },
  devtool: 'source-map',
  resolve: { extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'] },
  plugins: [
    new webpack.ProvidePlugin({
      process: 'process/browser',
    }),
  ],
};

Solved!

Screenshot 2021-02-16 at 7 26 37 PM
Deep-Codes commented 3 years ago

Hope this Helps 👍🏽

KaiHotz commented 3 years ago

@Deep-Codes thanks for the PR and the Fix, PR got approved and merged. Had to do a bit of cleanup since there was a package-lock and yarn.lock file. I'm glad you liked it and also thankful for your contribution.