Next.js: Upgrade from next v7.2.0 to next v8.0.6-canary, _app.js conflict with webpack resolve config

Created on 14 Jan 2019  路  5Comments  路  Source: vercel/next.js

Bug report

Describe the bug

If next.config.js consist of resolve rules, and have a _app.js, it will give error during compling as following.

This dependency was not found:

* private-next-pages/_app.js in ./node_modules/next/dist/build/webpack/loaders/next-client-pages-loader.js?page=%2F_app&absolutePagePath=private-next-pages%2F_app.js

To install it, you can run: npm install --save private-next-pages/_app.js

To Reproduce

  1. Clone the repo
    https://github.com/roytsang/bug-report/tree/master/next-v8-canary-appjs

  2. Ensure there is _app.js under pages forlder

  3. Ensure there is resolve rules in next.config.js

  4. Run npm run dev, it will give the above error in console

  5. With either one will not trigger the error

Expected behavior

The code in the repo should not give error, it is work before upgrade.

Most helpful comment

@timneutkens I'm having the same issue, can you advise on the proper solution?

I assume the Next.js aliases already exist by the time our webpack function executes?

So, should we do something like the following:

module.exports = {
  // ... other next.js config
  return {
    webpack: config => {
      config.resolve.alias = {
            ...(config.resolve.alias || {}),
            // custom webpack aliases
      }
      return config
    }
  }
}

All 5 comments

Note that this is not a bug, you're overriding the webpack config at your own risk and it can be backwards incompatible if you're not taking into account that values might change. In this case you're not taking into account that Next.js might set aliases in the config, which you also have to add.

@timneutkens I'm having the same issue, can you advise on the proper solution?

I assume the Next.js aliases already exist by the time our webpack function executes?

So, should we do something like the following:

module.exports = {
  // ... other next.js config
  return {
    webpack: config => {
      config.resolve.alias = {
            ...(config.resolve.alias || {}),
            // custom webpack aliases
      }
      return config
    }
  }
}

correct, that's what you should do.

https://github.com/zeit/next.js/issues/6051#issuecomment-462934252

This solution worked for me, just had to change Obect to Object.

I've updated @NathanielHill's comment to use spread syntax

Was this page helpful?
0 / 5 - 0 ratings