0

I have an app which is created with Create Inferno App. I ejected at some point to customize build configs. Now I am trying to upgrade dependencies to the latest versions and replace deprecated dependencies. When trying to build my app. I get this error:

yarn run v1.22.19
$ INLINE_RUNTIME_CHUNK=false node scripts/devbuild.js
Creating a development build...
Failed to compile.

Error: [BABEL] /home/farooqkz/playground/chooj/src/index.js: Unknown option: .config. Check out https://babeljs.io/docs/en/babel-core/#options for more information about options.


error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Unfortunately, the error message doesn't say where does it come from. Here's my package.json:

{
  "name": "chooj",
  "version": "0.0.0",
  "private": true,
  "dependencies": {
    "@svgr/webpack": "^6.5.1",
    "KaiUI": "git+https://github.com/farooqkz/KaiUIv2.git",
    "@babel/core": "^7.20.2",
    "@babel/eslint-parser": "^7.19.0",
    "babel-loader": "8.0.4",
    "babel-preset-inferno-app": "^8.0.3",
    "bfj": "^7.0.0",
    "case-sensitive-paths-webpack-plugin": "2.4.0",
    "chalk": "2.4.1",
    "classnames": "^2.3.1",
    "core-js": "^3.26.1",
    "css-loader": "^6.7.0",
    "dotenv": "16.0.3",
    "dotenv-expand": "9.0.0",
    "eslint": "^8.27.0",
    "eslint-config-inferno-app": "^7.0.2",
    "eslint-webpack-plugin": "3.2.0",
    "eslint-plugin-flowtype": "^8.0.0",
    "eslint-plugin-import": "2.14.0",
    "eslint-plugin-inferno": "^7.11.0",
    "eslint-plugin-jsx-a11y": "6.1.2",
    "file-loader": "^6.2.0",
    "fs-extra": "7.0.1",
    "html-webpack-plugin": "5.5.0",
    "identity-obj-proxy": "3.0.0",
    "inferno": "^8.0.0",
    "inferno-dev-utils": "^6.0.4",
    "inferno-extras": "^8.0.0",
    "jsqr": "^1.4.0",
    "localforage": "^1.9.0",
    "matrix-js-sdk": "^21.1.0",
    "mini-css-extract-plugin": "^2.6.0",
    "css-minimizer-webpack-plugin": "4.2.2",
    "pnp-webpack-plugin": "1.7.0",
    "postcss-flexbugs-fixes": "4.1.0",
    "postcss-loader": "^7.0.0",
    "postcss-preset-env": "^7.8.0",
    "postcss-safe-parser": "^6.0.0",
    "prettier": "^2.3.2",
    "querystring-browser": "^1.0.4",
    "react-app-polyfill": "^3.0.0",
    "resolve": "^1.22.0",
    "sass-loader": "^13.0.0",
    "style-loader": "^3.3.0",
    "terser-webpack-plugin": "5.3.6",
    "url-loader": "1.1.2",
    "webpack": "^5.75.0",
    "webpack-dev-server": "^4.11.1"
  },
  "scripts": {
    "start": "node scripts/start.js",
    "devbuild": "INLINE_RUNTIME_CHUNK=false node scripts/devbuild.js"
  },
  "eslintConfig": {
    "extends": "inferno-app"
  },
  "browserslist": "ff 48",
  "babel": {
    "presets": [
      "inferno-app"
    ]
  },
  "devDependencies": {
    "babel-plugin-transform-replace-expressions": "^0.2.0"
  }
}

And here's the webpack config I use:

'use strict';

const path = require('path');
const webpack = require('webpack');
const PnpWebpackPlugin = require('pnp-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const InterpolateHtmlPlugin = require('inferno-dev-utils/InterpolateHtmlPlugin');
const WatchMissingNodeModulesPlugin = require('inferno-dev-utils/WatchMissingNodeModulesPlugin');
const ModuleScopePlugin = require('inferno-dev-utils/ModuleScopePlugin');
const getCSSModuleLocalIdent = require('inferno-dev-utils/getCSSModuleLocalIdent');
const getClientEnvironment = require('./env');
const paths = require('./paths');
const ModuleNotFoundPlugin = require('inferno-dev-utils/ModuleNotFoundPlugin');


// Webpack uses `publicPath` to determine where the app is being served from.
// In development, we always serve from the root. This makes config easier.
const publicPath = '/';
// `publicUrl` is just like `publicPath`, but we will provide it to our app
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
// Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
const publicUrl = '';
// Get environment variables to inject into our app.
const env = getClientEnvironment(publicUrl);

// style files regexes
const cssRegex = /\.css$/;
const cssModuleRegex = /\.module\.css$/;
const sassRegex = /\.(scss|sass)$/;
const sassModuleRegex = /\.module\.(scss|sass)$/;

// common function to get style loaders
const getStyleLoaders = (cssOptions, preProcessor) => {
  const loaders = [
    require.resolve('style-loader'),
    {
      loader: require.resolve('css-loader'),
      options: cssOptions,
    },
    {
      // Options for PostCSS as we reference these options twice
      // Adds vendor prefixing based on your specified browser support in
      // package.json
      loader: require.resolve('postcss-loader'),
      options: {
        // Necessary for external CSS imports to work
        // https://github.com/facebook/create-react-app/issues/2677
        ident: 'postcss',
        plugins: () => [
          require('postcss-flexbugs-fixes'),
          require('postcss-preset-env')({
            autoprefixer: {
              flexbox: 'no-2009',
            },
            stage: 3,
          }),
        ],
      },
    },
  ];
  if (preProcessor) {
    loaders.push(require.resolve(preProcessor));
  }
  return loaders;
};

// This is the development configuration.
// It is focused on developer experience and fast rebuilds.
// The production configuration is different and lives in a separate file.
module.exports = {
  mode: 'development',
  // These are the "entry points" to our application.
  // This means they will be the "root" imports that are included in JS bundle.
  entry: [
    // Include an alternative client for WebpackDevServer. A client's job is to
    // connect to WebpackDevServer by a socket and get notified about changes.
    // When you save a file, the client will either apply hot updates (in case
    // of CSS changes), or refresh the page (in case of JS changes). When you
    // make a syntax error, this client will display a syntax error overlay.
    // Note: instead of the default WebpackDevServer client, we use a custom one
    // to bring better experience for Create Inferno App users. You can replace
    // the line below with these two lines if you prefer the stock client:
    // require.resolve('webpack-dev-server/client') + '?/',
    // require.resolve('webpack/hot/dev-server'),
    //require.resolve('inferno-dev-utils/webpackHotDevClient'),
    // Finally, this is your app's code:
    paths.appIndexJs,
    // We include the app code last so that if there is a runtime error during
    // initialization, it doesn't blow up the WebpackDevServer client, and
    // changing JS code would still trigger a refresh.
  ],
  output: {
    // Add /* filename */ comments to generated require()s in the output.
    path: paths.appBuild,
    pathinfo: true,
    // This does not produce a real file. It's just the virtual path that is
    // served by WebpackDevServer in development. This is the JS bundle
    // containing code from all our entry points, and the Webpack runtime.
    filename: 'static/js/[name].[fullhash:6].js',
    // There are also additional JS chunk files if you use code splitting.
    chunkFilename: 'static/js/[id].[chunkhash].js',
    // This is the URL that app is served from. We use "/" in development.
    publicPath: publicPath,
    // Point sourcemap entries to original disk location (format as URL on Windows)
    devtoolModuleFilenameTemplate: info =>
      path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'),
  },
  optimization: {
    // Automatically split vendor and commons
    // https://twitter.com/wSokra/status/969633336732905474
    // https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366
    splitChunks: {
      chunks: 'all',
      name: false,
    },
    runtimeChunk: false,
  },
  resolve: {
    // This allows you to set a fallback for where Webpack should look for modules.
    // We placed these paths second because we want `node_modules` to "win"
    // if there are any conflicts. This matches Node resolution mechanism.
    // https://github.com/facebook/create-react-app/issues/253
    modules: ['node_modules'].concat(
      // It is guaranteed to exist because we tweak it in `env.js`
      process.env.NODE_PATH.split(path.delimiter).filter(Boolean)
    ),
    // These are the reasonable defaults supported by the Node ecosystem.
    // We also include JSX as a common component filename extension to support
    // some tools, although we do not recommend using it, see:
    // https://github.com/facebook/create-react-app/issues/290
    // `web` extension prefixes have been added for better support
    // for React Native Web.
    extensions: ['.mjs', '.web.js', '.js', '.json', '.web.jsx', '.jsx'],
    alias: {
      react: 'inferno-compat',
      'react-dom': 'inferno-compat',
      // These aliases makes sure all inferno imports and react aliases resolve into same script entry and no duplicates are made
      inferno: path.resolve(require.resolve('inferno/dist/index.dev.esm.js')),
      // 'inferno-clone-vnode': path.resolve(require.resolve('inferno-clone-vnode/dist/index.dev.esm.js')),
      // 'inferno-compat': path.resolve(require.resolve('inferno-compat/dist/index.dev.esm.js')),
      // 'inferno-component': path.resolve(require.resolve('inferno-component/dist/index.dev.esm.js')),
      // 'inferno-create-class': path.resolve(require.resolve('inferno-create-class/dist/index.dev.esm.js')),
      // 'inferno-create-element': path.resolve(require.resolve('inferno-create-element/dist/index.dev.esm.js')),
      // 'inferno-devtools': path.resolve(require.resolve('inferno-devtools/dist/index.dev.esm.js')),
      // 'inferno-extras': path.resolve(require.resolve('inferno-extras/dist/index.dev.esm.js')),
      // 'inferno-hydrate': path.resolve(require.resolve('inferno-hydrate/dist/index.dev.esm.js')),
      // 'inferno-hyperscript': path.resolve(require.resolve('inferno-hyperscript/dist/index.dev.esm.js')),
      // 'inferno-mobx': path.resolve(require.resolve('inferno-mobx/dist/index.dev.esm.js')),
      // 'inferno-redux': path.resolve(require.resolve('inferno-redux/dist/index.dev.esm.js')),
      // 'inferno-router': path.resolve(require.resolve('inferno-router/dist/index.dev.esm.js')),
      // 'inferno-server': path.resolve(require.resolve('inferno-server/dist/index.dev.esm.js')),
      // 'inferno-test-utils': path.resolve(require.resolve('inferno-test-utils/dist/index.dev.esm.js')),
      // 'inferno-vnode-flags': path.resolve(require.resolve('inferno-vnode-flags/dist/index.dev.esm.js'))
    },
    plugins: [
      // Adds support for installing with Plug'n'Play, leading to faster installs and adding
      // guards against forgotten dependencies and such.
      //PnpWebpackPlugin,
      // Prevents users from importing files from outside of src/ (or node_modules/).
      // This often causes confusion because we only process files within src/ with babel.
      // To fix this, we prevent you from importing files out of src/ -- if you'd like to,
      // please link the files into your node_modules/ and let module-resolution kick in.
      // Make sure your source files are compiled, as they will not be processed in any way.
      new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]),
    ],
  },
  resolveLoader: {
    modules: ['node_modules'],
    extensions: ['.js', '.json'],
    mainFields: ['loader', 'main'],
    plugins: [
      // Also related to Plug'n'Play, but this time it tells Webpack to load its loaders
      // from the current package.
      PnpWebpackPlugin.moduleLoader(module),
    ],
  },
  module: {
    strictExportPresence: true,
    rules: [
      // Disable require.ensure as it's not a standard language feature.
      { parser: { requireEnsure: false } },
      {
        // "oneOf" will traverse all following loaders until one will
        // match the requirements. When no loader matches it will fall
        // back to the "file" loader at the end of the loader list.
        oneOf: [
          // "url" loader works like "file" loader except that it embeds assets
          // smaller than specified limit in bytes as data URLs to avoid requests.
          // A missing `test` is equivalent to a match.
          {
            test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
            loader: require.resolve('url-loader'),
            options: {
              limit: 10000,
              name: 'static/media/[name].[hash:8].[ext]',
            },
          },
          // Process application JS with Babel.
          // The preset includes JSX, Flow, and some ESnext features.
          {
            test: /\.(js|mjs|jsx)$/,
            include: paths.appSrc,
            loader: require.resolve('babel-loader'),
            options: {
              presets: [
                'babel-preset-inferno-app/webpack-overrides'
              ],
              
              // This is a feature of `babel-loader` for webpack (not Babel itself).
              // It enables caching results in ./node_modules/.cache/babel-loader/
              // directory for faster rebuilds.
              cacheDirectory: true,
              // Don't waste time on Gzipping the cache
              cacheCompression: false,
            },
          },
          // Process any JS outside of the app with Babel.
          // Unlike the application JS, we only compile the standard ES features.
          {
            test: /\.(js|mjs)$/,
            exclude: /@babel(?:\/|\\{1,2})runtime/,
            include: /node_modules\/.+\.js$/,
            loader: require.resolve('babel-loader'),
            options: {
              babelrc: false,
              configFile: false,
              compact: false,
              presets: [
                [
                  'babel-preset-inferno-app/dependencies',
                  { helpers: true },
                ],
              ],
              cacheDirectory: true,
              // Don't waste time on Gzipping the cache
              cacheCompression: false,
              
              // If an error happens in a package, it's possible to be
              // because it was compiled. Thus, we don't want the browser
              // debugger to show the original code. Instead, the code
              // being evaluated would be much more helpful.
              sourceMaps: false,
            },
          },
          // "postcss" loader applies autoprefixer to our CSS.
          // "css" loader resolves paths in CSS and adds assets as dependencies.
          // "style" loader turns CSS into JS modules that inject <style> tags.
          // In production, we use a plugin to extract that CSS to a file, but
          // in development "style" loader enables hot editing of CSS.
          // By default we support CSS Modules with the extension .module.css
          {
            test: cssRegex,
            exclude: cssModuleRegex,
            use: getStyleLoaders({
              importLoaders: 1,
            }),
          },
          // Adds support for CSS Modules (https://github.com/css-modules/css-modules)
          // using the extension .module.css
          {
            test: cssModuleRegex,
            use: getStyleLoaders({
              importLoaders: 1,
              modules: true,
              getLocalIdent: getCSSModuleLocalIdent,
            }),
          },
          // Opt-in support for SASS (using .scss or .sass extensions).
          // Chains the sass-loader with the css-loader and the style-loader
          // to immediately apply all styles to the DOM.
          // By default we support SASS Modules with the
          // extensions .module.scss or .module.sass
          {
            test: sassRegex,
            exclude: sassModuleRegex,
            use: getStyleLoaders({ importLoaders: 2 }, 'sass-loader'),
          },
          // Adds support for CSS Modules, but using SASS
          // using the extension .module.scss or .module.sass
          {
            test: sassModuleRegex,
            use: getStyleLoaders(
              {
                importLoaders: 2,
                modules: true,
                getLocalIdent: getCSSModuleLocalIdent,
              },
              'sass-loader'
            ),
          },
          // "file" loader makes sure those assets get served by WebpackDevServer.
          // When you `import` an asset, you get its (virtual) filename.
          // In production, they would get copied to the `build` folder.
          // This loader doesn't use a "test" so it will catch all modules
          // that fall through the other loaders.
          {
            // Exclude `js` files to keep "css" loader working as it injects
            // its runtime that would otherwise be processed through "file" loader.
            // Also exclude `html` and `json` extensions so they get processed
            // by webpacks internal loaders.
            exclude: [/\.(js|mjs|jsx)$/, /\.html$/, /\.json$/],
            loader: require.resolve('file-loader'),
            options: {
              name: 'static/media/[name].[hash:8].[ext]',
            },
          },
        ],
      },
      // ** STOP ** Are you adding a new loader?
      // Make sure to add the new loader(s) before the "file" loader.
    ],
  },
  plugins: [
    // Generates an `index.html` file with the <script> injected.
    new HtmlWebpackPlugin({
      inject: true,
      template: paths.appHtml,
    }),
    // Makes some environment variables available in index.html.
    // The public URL is available as %PUBLIC_URL% in index.html, e.g.:
    // <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
    // In development, this will be an empty string.
    new InterpolateHtmlPlugin(HtmlWebpackPlugin, env.raw),
    // This gives some necessary context to module not found errors, such as
    // the requesting resource.
    new ModuleNotFoundPlugin(paths.appPath),
    // Makes some environment variables available to the JS code, for example:
    // if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
    new webpack.DefinePlugin(env.stringified),
    // This is necessary to emit hot updates (currently CSS only):
    //new webpack.HotModuleReplacementPlugin(),
    // Watcher doesn't work well if you mistype casing in a path so we use
    // a plugin that prints an error when you attempt to do this.
    // See https://github.com/facebook/create-react-app/issues/240
    new CaseSensitivePathsPlugin(),
    // If you require a missing module and then `npm install` it, you still have
    // to restart the development server for Webpack to discover it. This plugin
    // makes the discovery automatic so you don't have to restart.
    // See https://github.com/facebook/create-react-app/issues/186
    new WatchMissingNodeModulesPlugin(paths.appNodeModules),
    // Moment.js is an extremely popular library that bundles large locale files
    // by default due to how Webpack interprets its code. This is a practical
    // solution that requires the user to opt into importing specific locales.
    // https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
    new ESLintPlugin(),
  ],

  // Turn off performance processing because we utilize
  // our own hints via the FileSizeReporter
  performance: false,
};

And finally, the build script itself:

'use strict';

// Do this as the first thing so that any code reading it knows the right env.
process.env.BABEL_ENV = 'development';
process.env.NODE_ENV = 'development';

// Ensure environment variables are read.
require('../config/env');


const path = require('path');
const chalk = require('chalk');
const fs = require('fs-extra');
const webpack = require('webpack');
const bfj = require('bfj');
const config = require('../config/webpack.config.devbuild');
const paths = require('../config/paths');
const checkRequiredFiles = require('inferno-dev-utils/checkRequiredFiles');
const formatWebpackMessages = require('inferno-dev-utils/formatWebpackMessages');
const printHostingInstructions = require('inferno-dev-utils/printHostingInstructions');
const FileSizeReporter = require('inferno-dev-utils/FileSizeReporter');
const printBuildError = require('inferno-dev-utils/printBuildError');

const measureFileSizesBeforeBuild =
  FileSizeReporter.measureFileSizesBeforeBuild;
const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild;
const useYarn = fs.existsSync(paths.yarnLockFile);

// These sizes are pretty large. We'll warn for bundles exceeding them.
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;

const isInteractive = process.stdout.isTTY;

// Warn and crash if required files are missing
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
  process.exit(1);
}

// Process CLI arguments
const argv = process.argv.slice(2);
const writeStatsJson = argv.indexOf('--stats') !== -1;

// We require that you explictly set browsers and do not fall back to
// browserslist defaults.
const { checkBrowsers } = require('inferno-dev-utils/browsersHelper');
checkBrowsers(paths.appPath, isInteractive)
  .then(() => {
    // First, read the current file sizes in build directory.
    // This lets us display how much they changed later.
    return measureFileSizesBeforeBuild(paths.appBuild);
  })
  .then(previousFileSizes => {
    // Remove all content but keep the directory so that
    // if you're in it, you don't end up in Trash
    fs.emptyDirSync(paths.appBuild);
    // Merge with the public folder
    copyPublicFolder();
    // Start the webpack build
    return build(previousFileSizes);
  })
  .then(
    ({ stats, previousFileSizes, warnings }) => {
      if (warnings.length) {
        console.log(chalk.yellow('Compiled with warnings.\n'));
        console.log(warnings.join('\n\n'));
        console.log(
          '\nSearch for the ' +
            chalk.underline(chalk.yellow('keywords')) +
            ' to learn more about each warning.'
        );
        console.log(
          'To ignore, add ' +
            chalk.cyan('// eslint-disable-next-line') +
            ' to the line before.\n'
        );
      } else {
        console.log(chalk.green('Compiled successfully.\n'));
      }

      console.log('File sizes after gzip:\n');
      printFileSizesAfterBuild(
        stats,
        previousFileSizes,
        paths.appBuild,
        WARN_AFTER_BUNDLE_GZIP_SIZE,
        WARN_AFTER_CHUNK_GZIP_SIZE
      );
      console.log();

      const appPackage = require(paths.appPackageJson);
      const publicUrl = paths.publicUrl;
      const publicPath = config.output.publicPath;
      const buildFolder = path.relative(process.cwd(), paths.appBuild);
      printHostingInstructions(
        appPackage,
        publicUrl,
        publicPath,
        buildFolder,
        useYarn
      );
    },
    err => {
      console.log(chalk.red('Failed to compile.\n'));
      printBuildError(err);
      process.exit(1);
    }
  )
  .catch(err => {
    if (err && err.message) {
      console.log(err.message);
    }
    process.exit(1);
  }).then(() => {
    let jsFile = paths.appBuild + '/static/js/0.chunk.js';
    fs.readFile(jsFile).then(buf => {
      let s = buf.toString();
      s = s.replace('new XHR()', 'new XHR({mozSystem:true})');
      s = s.replace('new global.XMLHttpRequest()', 'new global.XMLHttpRequest({mozSystem:true})');
      // These two "replace"s are necessary to make WebRTC fully work on KaiOS pre-3.0
      s = s.replace(/setRemoteDescription\(([a-zA-Z0-9\.]+)\)/g, (match, p1) => {
        return `setRemoteDescription(new RTCSessionDescription(${p1}))`;
      });
      s = s.replace(/addIceCandidate\(([a-zA-Z0-9\.]+)\)/g, (match, p1) => {
        return `addIceCandidate(new RTCIceCandidate(${p1}))`;
      });
      s = s.replace("!(!remoteStream", "(!remoteStream");
      fs.writeFile(jsFile, s).catch(err => {
        if (err && err.message) {
          console.log(err.message);
        }
      });
    });
  });

// Create the production build and print the deployment instructions.
function build(previousFileSizes) {
  console.log('Creating a development build...');

  let compiler = webpack(config);
  return new Promise((resolve, reject) => {
    compiler.run((err, stats) => {
      let messages;
      if (err) {
        if (!err.message) {
          return reject(err);
        }
        messages = formatWebpackMessages({
          errors: [err.message],
          warnings: [],
        });
      } else {
        messages = formatWebpackMessages(
          stats.toJson({ all: false, warnings: true, errors: true })
        );
      }
      if (messages.errors.length) {
        // Only keep the first error. Others are often indicative
        // of the same problem, but confuse the reader with noise.
        if (messages.errors.length > 1) {
          messages.errors.length = 1;
        }
        return reject(new Error(messages.errors.join('\n\n')));
      }
      if (
        process.env.CI &&
        (typeof process.env.CI !== 'string' ||
          process.env.CI.toLowerCase() !== 'false') &&
        messages.warnings.length
      ) {
        console.log(
          chalk.yellow(
            '\nTreating warnings as errors because process.env.CI = true.\n' +
              'Most CI servers set it automatically.\n'
          )
        );
        return reject(new Error(messages.warnings.join('\n\n')));
      }

      const resolveArgs = {
        stats,
        previousFileSizes,
        warnings: messages.warnings,
      };
      if (writeStatsJson) {
        return bfj
          .write(paths.appBuild + '/bundle-stats.json', stats.toJson())
          .then(() => resolve(resolveArgs))
          .catch(error => reject(new Error(error)));
      }

      return resolve(resolveArgs);
    });
  });
}

function copyPublicFolder() {
  fs.copySync(paths.appPublic, paths.appBuild, {
    dereference: true,
    filter: file => file !== paths.appHtml,
  });
}

0 Answers0