vercel / webpack-asset-relocator-loader

Used in ncc while emitting and relocating any asset references
https://npmjs.com/@vercel/webpack-asset-relocator-loader
MIT License
99 stars 32 forks source link

Regression 1.7.3 to 1.7.4: __nccwpck_require__ is not defined #188

Open vieira opened 4 months ago

vieira commented 4 months ago

After updating from @vercel/webpack-asset-relocator-loader 1.7.3 to 1.7.4 the build still succeeds but the generated bundle now fails to start with the following error:

/Users/.../dist/index.js:198193
const googleProtoFilesDir = __nccwpck_require__.ab + "protos";
                            ^

ReferenceError: __nccwpck_require__ is not defined
    at 38020 (/Users/.../api/dist/index.js:198193:29)
    at __webpack_require__ (/Users/.../dist/index.js:774516:42)
    at 52013 (/Users/.../api/dist/index.js:198899:16)
    at __webpack_require__ (/Users/.../dist/index.js:774516:42)
    at new LanguageServiceClient (/Users/.../dist/index.js:50263:27)
    at 80046 (/Users/.../dist/index.js:661168:16)
    at __webpack_require__ (/Users/.../dist/index.js:774516:42)
    at 49801 (/Users/.../dist/index.js:661353:38)
    at __webpack_require__ (/Users/.../dist/index.js:774516:42)
    at 96739 (/Users/.../dist/index.js:660922:49)

Relevant webpack configuration:

const webpack = require('webpack');

module.exports = {
  entry: './index.js',
  target: 'node20',
  node: false,
  devtool: false,
  resolve: {
    mainFields: ['main', 'module'],
  },
  // ...
  optimization: {
    minimize: false,
  },
  module: {
    rules: [
      {
        test: /\.mjs$/,
        type: 'javascript/auto',
      },
      {
        test: /\.m?js?$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: { rootMode: 'upward' },
        },
      },
      {
        test: /\.(m?js|node)$/,
        parser: { amd: false },
        use: {
          loader: '@vercel/webpack-asset-relocator-loader',
          options: {},
        },
      },
    ],
  },
  stats: {
    warnings: false,
  },
}

Downgrading to 1.7.3 fixes the issue, without any other changes.

styfle commented 4 months ago

This might be related to the upgrade to ncc. I was surprised to find it there because we have a circular dependency:

I was forced to upgrade ncc in this repo since it was using a really old version that didn't support newer Node.js versions.

@guybedford Do you recall why ncc is needed? Can we drop it?

linonetwo commented 2 months ago

Thank you! Downgrade to @vercel/webpack-asset-relocator-loader 1.7.3 fix this for me, thank you for posting this issue so I can google here!