Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom .babelrc file not being loaded after upgrading to Next.js 11 #26539

Open
AndreSilva1993 opened this issue Jun 23, 2021 · 20 comments
Open
Labels
bug Issue was opened via the bug report template. Webpack Related to Webpack with Next.js.

Comments

@AndreSilva1993
Copy link

AndreSilva1993 commented Jun 23, 2021

What version of Next.js are you using?

11.0.1

What version of Node.js are you using?

12.16.1

What browser are you using?

Chrome

What operating system are you using?

macOS

How are you deploying your application?

Other platform

Describe the Bug

Before upgrading to Next.js 11, my custom .babelrc file (which sits in the project's root directory) would be picked up by and used. When I booted up the project, I would always receive this message:

screenshot

However, after upgrading to 11, I no longer get this message when booting up the application and Emotion started complaining about some features that require the usage of their @emotion/babel-plugin which leads me to believe that the Babel custom configuration is not being picked up. I do have a custom server and my .babelrc looks like this:

{
  "plugins": ["@emotion/babel-plugin"],
  "presets": [
    [
      "next/babel",
      {
        "preset-react": {
          "runtime": "automatic",
          "importSource": "@emotion/react"
        }
      }
    ]
  ],
  "env": {
    "test": {
      "plugins": ["babel-plugin-dynamic-import-node"]
    }
  }
}

Expected Behavior

Next.js application would pick up the .babelrc file like it's stated in its documentation and like it happened in v10.

To Reproduce

https://stackblitz.com/edit/nextjs-h1ihd3

In here I added a simple custom server that I took directly from your documentation and you can see that the message about the custom .babelrc being picked up, does not appear. You just need to run node server.js in the terminal.

@AndreSilva1993 AndreSilva1993 added the bug Issue was opened via the bug report template. label Jun 23, 2021
timneutkens added a commit to timneutkens/next.js that referenced this issue Jun 24, 2021
Partially solves vercel#26539 by adding back the log output when a config file is used
@timneutkens timneutkens added kind: bug and removed bug Issue was opened via the bug report template. labels Jun 24, 2021
@timneutkens timneutkens added this to the Iteration 22 milestone Jun 24, 2021
@timneutkens
Copy link
Member

timneutkens commented Jun 24, 2021

The new babel loader does not have the log line the old one had. So I've opened a PR to add it: #26570. It is picking up the particular babelrc from the reproduction though 👍 E.g. try adding a syntax error in .babelrc of the reproduction and refreshing, you'll see that it does not load.

@AndreSilva1993
Copy link
Author

Yeah, you're right. Then I'm not exactly sure of what's happening in my project because I'm getting this error Component selectors can only be used in conjunction with @emotion/babel-plugin which I never faced since I always had the Emotion babel plugin configured. Perhaps I could wait for your PR to be certain that the .babelrc is indeed being loaded or not?

@JesseVelden
Copy link

I also have the same problem that I think my .babelrc is not loaded with the @emotion/babel-plugin in particular. I debugged it by adding some console.log statements in a .babelrc.js file, and that seems to be working. Unfortunately the page is getting no styles as I am relying on @emotion/babel-plugin for styles.

I tried to make a small reproduction example, but my fresh next.js project seems to be working fine. I am not sure what is going wrong then, but got the same problem as @AndreSilva1993.

@AndreSilva1993
Copy link
Author

AndreSilva1993 commented Jun 24, 2021

I also have the same problem that I think my .babelrc is not loaded with the @emotion/babel-plugin in particular. I debugged it by adding some console.log statements in a .babelrc.js file, and that seems to be working. Unfortunately the page is getting no styles as I am relying on @emotion/babel-plugin for styles.

I tried to make a small reproduction example, but my fresh next.js project seems to be working fine. I am not sure what is going wrong then, but got the same problem as @AndreSilva1993.

Can confirm this as well, the file is actually picked up as I also added a console.log in there which correctly appears when booting up the application. So could this be an issue specific to the @emotion/babel-plugin or something related to the new babel loader which broke this plugin in particular?

kodiakhq bot pushed a commit that referenced this issue Jun 24, 2021
Partially solves #26539 by adding back the log output when a config file is used



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes
@JesseVelden
Copy link

JesseVelden commented Jun 24, 2021

I also have the same problem that I think my .babelrc is not loaded with the @emotion/babel-plugin in particular. I debugged it by adding some console.log statements in a .babelrc.js file, and that seems to be working. Unfortunately the page is getting no styles as I am relying on @emotion/babel-plugin for styles.
I tried to make a small reproduction example, but my fresh next.js project seems to be working fine. I am not sure what is going wrong then, but got the same problem as @AndreSilva1993.

Can confirm this as well, the file is actually picked up as I also added a console.log in there which correctly appears when booting up the application. So could this be an issue specific to the @emotion/babel-plugin or something related to the new babel loader which broke this plugin in particular?

I think the new babel loader doesn't pick it up in our particular projects as I tried to make an reproduction, but that did actually work even with the @emotion/babel-plugin.

@AndreSilva1993 do you also have multiple babel files through your entire project? (that could be the case for example if you have a monorepo). Maybe the new babel loader, somehow loads the file but ditches it for another one.

@AndreSilva1993
Copy link
Author

AndreSilva1993 commented Jun 24, 2021

I also have the same problem that I think my .babelrc is not loaded with the @emotion/babel-plugin in particular. I debugged it by adding some console.log statements in a .babelrc.js file, and that seems to be working. Unfortunately the page is getting no styles as I am relying on @emotion/babel-plugin for styles.
I tried to make a small reproduction example, but my fresh next.js project seems to be working fine. I am not sure what is going wrong then, but got the same problem as @AndreSilva1993.

Can confirm this as well, the file is actually picked up as I also added a console.log in there which correctly appears when booting up the application. So could this be an issue specific to the @emotion/babel-plugin or something related to the new babel loader which broke this plugin in particular?

I think the new babel loader doesn't pick it up in our particular projects as I tried to make an reproduction, but that did actually work even with the @emotion/babel-plugin.

@AndreSilva1993 do you also have multiple babel files through your entire project? (that could be the case for example if you have a monorepo). Maybe the new babel loader, somehow loads the file but ditches it for another one.

I had another .babelrc for the server which sits in the src/server folder while the client one sits in the root directory. Tried adding the @emotion/babel-plugin to the server one just to test it out and the error persists. However the Next.js should only pick up the one present in the root directory 🤔

@timleppard
Copy link

FWIW I was experiencing this with next build after upgrading, removing the old .next/ build directory resolved it.

@timneutkens
Copy link
Member

I've released a new canary version with my PR: https://github.com/vercel/next.js/releases/tag/v11.0.2-canary.1

You can try it out using yarn add next@canary (or npm install next@canary), takes a bit to be published (15-20mins). Let me know if that change helps 👍

@AndreSilva1993
Copy link
Author

I've released a new canary version with my PR: https://github.com/vercel/next.js/releases/tag/v11.0.2-canary.1

You can try it out using yarn add next@canary (or npm install next@canary), takes a bit to be published (15-20mins). Let me know if that change helps 👍

I installed the canary version and the message does not appear? However the console.log I put in there is successfully displayed? I changed the .babelrc to a .babelrc.js to this:

console.log('Please appear in the terminal');

module.exports = {
  plugins: ['@emotion/babel-plugin'],
  presets: [
    [
      'next/babel',
      {
        'preset-react': {
          runtime: 'automatic',
          importSource: '@emotion/react',
        },
      },
    ],
  ],
  env: {
    test: {
      plugins: ['babel-plugin-dynamic-import-node'],
    },
  },
};

This is what I see in the terminal:

Screenshot 2021-06-25 at 11 20 59

And to confirm that I had indeed installed the canary version I opened up the node_modules/next/package.json and this is what I see:

Screenshot 2021-06-25 at 11 21 58

So I'm really confused by this.

@JesseVelden
Copy link

Hmm, yes that is what I already thought that it wouldn't pick it up somehow. I will try to debug (maybe in the weekend if I have time) it in the get-config.ts and compare the results with the 10.2.3 version.

@AndreSilva1993
Copy link
Author

AndreSilva1993 commented Jun 25, 2021

@MegaCookie @timneutkens Managed to find out what the issue was. In my custom server I was changing the dir property which was not the same directory as the .babelrc lives in. Last version this was not an issue but on this major one, the getBaseWebpackConfig method looks for the custom Babel files inside this dir property. I don't know if this was an intentional change or if in the last version, I was taking advantage of an unexpected behaviour but these are my findings.

If I move the server.ts file into the root directory (it was in the src/server directory with the dir property pointing one folder above to the src/ folder) and remove the dir override, everything works as expected. And I think I'll leave it like this and just change my build process. Other solution which seems less contrived would be to just point the dir property to the correct folder while maintaining the rest of the project intact.

So basically what I found is that on Next.js 10 having the dir property not pointing to the folder where the .babelrc is, works unlike in Next.js 11.

@JesseVelden
Copy link

@MegaCookie @timneutkens Managed to find out what the issue was. In my custom server I was changing the dir property which was not the same directory as the .babelrc lives in. Last version this was not an issue but on this major one, the getBaseWebpackConfig method looks for the custom Babel files inside this dir property. I don't know if this was an intentional change or if in the last version, I was taking advantage of an unexpected behaviour but these are my findings.

If I move the server.ts file into the root directory and remove the dir override, everything works as expected. And I think I'll leave it like this and just change my build process.

Ah nice finding! I will also try it this weekend, and let you all know.

@JesseVelden
Copy link

JesseVelden commented Jun 26, 2021

It is quite interesting. I finally got version 11 to work in my project again. I had a next.config.js inside the src folder, but found out by the docs (https://nextjs.org/docs/advanced-features/src-directory) that it should actually be in the root directory. Then still my .babelrc file wasn't picked up by Next. When I placed it inside the src directory it started to actually pickup the .babelrc file.

This was the case in which I used Next in combination with a Custom (express) server.
So in my case the dir property of the nextApp was pointing to the wrong folder (in my case I added the /src in the dir option, but when removing this appendix, it had picked up the .babelrc file).
And also make sure your next.config.js is not in the src directory and change the distDir to just .next if needed. And additionally if you have a monorepo structure like me with a server and client repo, then all the babel plugins needs to be installed in the server repo if they are used by the Next.js client side.

It's a bit stupid but easily overlooked 😬, but I think the version 11 behaviour of only picking up a .babelrc file in the right directory makes more sense.

Maybe a note of this behaviour change on the upgrade documentation/ custom server docs will be a good addition.

@DaveStein
Copy link

DaveStein commented Jun 30, 2021

npx babel src/pages/index.tsx works for me.

When I run tests I get Add @babel/preset-react (https://git.io/JfeDR) to the 'presets' section of your Babel config to enable transformation. even though I have this setup:

// next.config.js
module.exports = {
  reactStrictMode: true,
};

// src/.babelrc or .babelrc in root
{
    "presets": [
        "next/babel"
    ]
}

// jest.config.js
module.exports = {
  preset: 'ts-jest',
  collectCoverageFrom: ['src/**/*.ts', 'src/**/*.tsx'],
  coveragePathIgnorePatterns: ['__mocks__']
};

@ssylvia
Copy link

ssylvia commented Jun 30, 2021

@timneutkens In my case, next seems to pick up my app's custom babel correctly but it does not find the other .babelrc files from the other monorepo packages that I'm transpiling with next-transpile-modules.

In next v10, I got the following output:

info  - Using external babel configuration from /Users/{username}/path-to-repo/monorepo-root-folder/packages/next-app/babel.config.js
info  - Using external babel configuration from /Users/{username}/path-to-repo/monorepo-root-folder/packages/components/.babelrc
info  - Using external babel configuration from /Users/{username}/path-to-repo/monorepo-root-folder/packages/shared/.babelrc
info  - Using external babel configuration from /Users/{username}/path-to-repo/monorepo-root-folder/packages/editor/.babelrc
info  - Using external babel configuration from /Users/{username}/path-to-repo/monorepo-root-folder/packages/utils/.babelrc

Now after upgrading to 11.0.2-canary-3, I get (notice all the same file):

info  - Using external babel configuration from /Users/{username}/path-to-repo/monorepo-root-folder/packages/next-app/babel.config.js
info  - Using external babel configuration from /Users/{username}/path-to-repo/monorepo-root-folder/packages/next-app/babel.config.js
info  - Using external babel configuration from /Users/{username}/path-to-repo/monorepo-root-folder/packages/next-app/babel.config.js
info  - Using external babel configuration from /Users/{username}/path-to-repo/monorepo-root-folder/packages/next-app/babel.config.js
info  - Using external babel configuration from /Users/{username}/path-to-repo/monorepo-root-folder/packages/next-app/babel.config.js
info  - Using external babel configuration from /Users/{username}/path-to-repo/monorepo-root-folder/packages/next-app/babel.config.js

I'm using a custom server, setting my dir prop to process.cwd(). And my directory structure at process.cwd() looks like:

# /Users/{username}/path-to-repo/monorepo-root-folder/packages/next-app
dist/index.js # custom node server
components/...
pages/...
public/...
babel.config.js
next.config.js
package.json

And my babel.config.js looks like:

module.exports = {
  babelrcRoots: [
    '.',
    '../utils',
    '../components',
    '../shared',
    '../editor',
  ],
  presets: ['next/babel', 'shared-config/babel/next-storymaps'],
}

leimonio added a commit to leimonio/next.js that referenced this issue Jul 6, 2021
* [WIP] Add cms notion integration example - index page

* Add cover images for pages

* Add post page

* Remove preview functionality

* Add module.exports to security headers documentation (vercel#26466)

Without `module.exports`, the provided code won't work if just pasted into `next.config.js`

## Documentation / Examples

- [x] Make sure the linting passes

* fix: ignore invalid accept-language header (vercel#26476)



Fixes vercel#22329

## Bug

- [x] Related issues linked using fixes vercel#22329
- [x] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes

* chore: Add Alex to lint documentation (vercel#26354)

This Pull Request adds [Alex](https://alexjs.com/) to our documentation. It catches insensitive, inconsiderate writing. 

The original PR (vercel#25821) is too large so I have decided to break it down into smaller PRs. This PR is the first part. Then I will continue to add the rest of the documentation in smaller PRs.

## More Information on Alex:
https://alexjs.com/
https://github.com/get-alex/alex

## Documentation / Examples

- [x] Make sure the linting passes

* Fix domain locales not available on client (vercel#26083)

* bug: Fix domain locales not available on client

* Add test case

* update tests

Co-authored-by: JJ Kasper <jj@jjsweb.site>

* Update to only add image import types when enabled (vercel#26485)

* Update to only add image import types when enabled

* add type check to test

* Update i18n fields in docs (vercel#26492)



Closes: vercel#24991

## Documentation / Examples

- [x] Make sure the linting passes

* v11.0.1-canary.7

* Strongly type `Router.events.on` and `Router.events.off` (vercel#26456)

This strongly types `Router.events.on` and `Router.events.off`. Previously the event type was `string` but now it's `'routeChangeStart' | 'beforeHistoryChange' | 'routeChangeComplete' | 'routeChangeError' | 'hashChangeStart' | 'hashChangeComplete'`


## Bug

- ~[ ] Related issues linked using `fixes #number`~
- [x] Integration tests added

Closes vercel#25679
Closes vercel#23753
Closes vercel#15497

* Update next Link & Image components

* Ensure image-types file is included (vercel#26495)

* Update react & react-dom to v17

* Update tailwind to use jit

* v11.0.1-canary.8

* v11.0.1

* Don't test image domains in test env (vercel#26502)

fixes vercel#21549

Co-authored-by: JJ Kasper <jj@jjsweb.site>

* docs: updated minimum Node.js version (vercel#26528)

## Documentation / Examples

- [x] Make sure the linting passes


According to new requirements in `package.json` minimum Node.js version for now is 12.0

* Update next-env note in docs (vercel#26536)

This ensures we don't recommend editing the `next-env` file since we need to be able to tweak it to accept future types we add in Next.js


## Documentation / Examples

- [x] Make sure the linting passes

Closes: vercel#26533

* [examples] Fix ssr-caching example. (vercel#26540)

Closes vercel#12019 with a better example of proper SSR caching.

* Fix props not updating when changing the locale and keeping hash (vercel#26205)



Currently, there is only a `hashChangeStart` and subsequent `hashChangeComplete` event and no props update (which would be used to get translations, etc.).
Happy for any feedback

fixes vercel#23467

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes

* Add note about adding additional types (vercel#26545)

* Add note about adding additional types

* Update to bold edit also

* Apply suggestions from code review

Co-authored-by: Steven <steven@ceriously.com>

* Allow user to override next-image-loader (vercel#26548)

In PR vercel#26281, we solved one use case but broke another.

This PR will allow the user to [override the built-in loader](vercel#26281 (comment)) via custom webpack config.

* v11.0.2-canary.0

* chore: Enable Alex documentation linting for error pages (vercel#26526)

* Update SWR example to include fetcher function. (vercel#26520)

* Previous example doesn't work

* Apply suggestions from code review

* Update docs/basic-features/data-fetching.md

* lint-fix

Co-authored-by: Lee Robinson <me@leerob.io>
Co-authored-by: JJ Kasper <jj@jjsweb.site>

* tailwind examps upgraded to v2.2 (vercel#26549)



## Documentation / Examples

- [x] Make sure the linting passes

* doc: prettify docs for next script (vercel#26572)



x-ref: vercel#26518 (comment)

## Documentation / Examples

- [x] Make sure the linting passes

* Add logging when a custom babelrc is loaded (vercel#26570)

Partially solves vercel#26539 by adding back the log output when a config file is used



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes

* Add comment to not edit in next-env file (vercel#26573)

This adds a comment to the generated `next-env.d.ts` to mention it should not be edited pointing to the documentation which contains an example of adding custom types separately. 

x-ref: vercel#26560

## Documentation / Examples

- [x] Make sure the linting passes

* Separate node polyfill test from basic suite (vercel#26550)

* Separate node polyfill test from basic suite

* update test

* fix with-loading example for next 11 (vercel#26569)

## Documentation / Examples

- [X] Make sure the linting passes

This PR updates the with-loading example to follow the documentation of router events for next 11

* v11.0.2-canary.1

* Add trace url on bootup (vercel#26594)

* Add trace url on bootup

* Update whitelist -> accesslist

* Add name to webpack-invalidated

* v11.0.2-canary.2

* Add check for ObjectExpression when iterating on <link> tags for font optimization (vercel#26608)

Fixes vercel#26547



## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes

* Enable Alex documentation linting for docs (vercel#26598)

* Add link to live demo already hosted (vercel#25718)

* Add link to live demo already hosted

To make it easier for people to simply see the live example without having to deploy a whole new project

* update link


Co-authored-by: JJ Kasper <jj@jjsweb.site>

* Update next/image docs for relative parent with layout=fill. (vercel#26615)

vercel#18739 (reply in thread)

* Fix GSP redirect cache error (vercel#26627)

This makes sure we don't attempt flushing cache info to disk for `getStaticProps` `redirect` items with `revalidate`

Fixes: vercel#20816

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added

* Correct statusCode when visiting _error directly (vercel#26610)

This fixes non-stop reloading when visiting `_error` directly in development caused by the `statusCode` being 200 unexpectedly while HMR returns the page as `invalid` which triggers `on-demand-entries` to reload the page. 

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added

Fixes: vercel#8036
x-ref: vercel#8033

* fix: next dynamic with jest (vercel#26614)



Fixes vercel#19862

Avoid executing `webpack` property on `loadableGenerated` of loadable component compiled from `next/dynamic` when `require.resolveWeak` is unavailable due to jest runtime missing `require.resolveWeak`.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] unit tests added

* Ensure API routes are not available under the locale (vercel#26629)

This ensures API routes are not available under the locale path since API routes don't need to be localized and we don't provide the locale to the API in any way currently so the user wouldn't be aware if the localized API route was visited instead of the non-localized. 

Fixes: vercel#25790

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added

* v11.0.2-canary.3

* Fix image content type octet stream 400 (vercel#26705)

Fixes vercel#23523 by adding image content type detection

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added

* Update layouts example to persist state across client-side transitions. (vercel#26706)

* Update layouts example

* Update examples/layout-component/components/layout.js

Co-authored-by: JJ Kasper <jj@jjsweb.site>

* Fix typo on "occured" to "occurred" (vercel#26709)

* fix: typo occured -> occurred

* fix: typo occured -> occurred

* fix: typo occured -> occurred

* fix: typo occured -> occurred

* lint-fix


Co-authored-by: JJ Kasper <jj@jjsweb.site>

* [ESLint] Adds --max-warnings flag to `next lint` (vercel#26697)

Adds `--max-warnings` flag to `next lint` to enable setting of a maximum warning threshold.

Fixes vercel#26671

* update with-redux-toolkit-typescript (vercel#26714)



## Bug

- [X] Related issues linked using `fixes vercel#26713 `

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [X] Make sure the linting passes

## Screenshots

After this small change the warning disappears.
![image](https://user-images.githubusercontent.com/47717492/123749377-fd56fb80-d8d2-11eb-8b70-dbb7f6f16050.png)

* Simplify `next-dev-server` implementation (vercel#26230)

`next-dev-server` having its own implementations of `renderToHTML` and `renderErrorToHTML` has historically made reasoning about streaming hard, as it adds additional places where status codes are explicitly set and the full HTML is blocked on.

Instead, this PR simplifies things considerably by moving the majority of the custom logic for e.g. hot reloading and on-demand compilation to when we're resolving the page to be loaded, rather than upfront when handling the request. It also cleans up a few other details (e.g. default error page rendering) that managed to creep into the base implementation over time.

One unfortunate side effect is that this makes compilation errors slightly more difficult. Previously, we'd render them directly. Now, we have to rethrow them. But since they've already been logged (by the watch pipeline), we have to make sure they don't get logged again.

* Update PR labeler action

* Simplify stats action (vercel#26751)

* Move code shared between server/client to "shared" folder (vercel#26734)

* Move next-server directory files to server directory (vercel#26756)

* Move next-server directory files to server directory

* Update tests

* Update paths in other places

* Support new hydrate API in latest react 18 alpha release (vercel#26664)

* fix: react 18 new hydration API

* support react 18

* compat latest react only, fix resolved version

* fix tests

* Some changes based on reactwg/react-18#5

* fix test

Co-authored-by: Tim Neutkens <timneutkens@me.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* Disable build-output size specific tests (vercel#26769)

* Disable build-output size specific tests

* remove size-limit test

* lint-fix

* Add upstream `max-age` to optimized image (vercel#26739)

This solves the main use case from Issue vercel#19914.

Previously, we would set the `Cache-Control` header to a constant and rely on the server cache. This would mean the browser would always request the image and the server could response with 304 Not Modified to omit the response body.

This PR changes the behavior such that the `max-age` will propagate from the upstream server to the Next.js Image Optimization Server and allow browser caching. ("upstream" meaning external server or just an internal route to an image)

This PR does not change the `max-age` for static imports which will remain `public, max-age=315360000, immutable`.

#### Pros:
- Fewer HTTP requests after initial browser visit
- User configurable `max-age` via the upstream image `Cache-Control` header

#### Cons:
- ~~Might be annoying for `next dev` when modifying a source image~~ (solved: use `max-age=0` for dev)
- Might cause browser to cache longer than expected (up to 2x longer than the server cache if requested in the last second before expiration)

## Bug

- [x] Related issues linked using `fixes #number`

* Fix blurred image position when using objectPosition (vercel#26590)



## Bug

fixes vercel#26309

## Documentation / Examples

see vercel#26309

- [ ] Make sure the linting passes

* Update azure tests (vercel#26779)

* Stabilize relay-analytics test (vercel#26782)

* Leverage blocked page for _error (vercel#26748)



## Enhance

simplify detection for visiting `_error`

x-ref: vercel#26610

* Update codeowners to add new maintainers (vercel#26770)

* examples: fix typo `lunix` → `linux` (vercel#26796)



## Bug

- [ ] ~~Related issues linked using `fixes #number`~~
- [ ] ~~Integration tests added~~

## Feature

- [ ] ~~Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.~~
- [ ] ~~Related issues linked using `fixes #number`~~
- [ ] ~~Integration tests added~~
- [ ] ~~Documentation added~~
- [ ] ~~Telemetry added. In case of a feature if it's used or not.~~

## Documentation / Examples

- [x] Make sure the linting passes

* Update repo scripts to separate folder (vercel#26787)

* fix: detect loop in client error page (vercel#26567)

Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>

* Update snapshot for font-optimization test (vercel#26823)

This fixes the `font-optimization` test failing from the links/content changing slightly in the snapshot. 

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes

* Add `onLoadingComplete()` prop to Image component (vercel#26824)

This adds a new prop, `onLoadingComplete()`, to handle the most common use case of `ref`.

I also added docs and a warning when using `ref` so we recommend the new prop instead.
 
- Fixes vercel#18398 
- Fixes vercel#22482

* Add "Vary: Accept" header to /_next/image responses (vercel#26788)

This pull request adds "Vary: Accept" header to responses from the image optimizer (i.e. the /_next/image endpoint).

The image optimizer prefers re-encoding JPG files to WebP, but some browsers (such as Safari 14 on Catalina) do not yet support WebP. In such cases the optimizer uses the Accept header sent by the browser to send out a JPG response. Thus the optimizer's response may depend on the Accept header.

Potential caching proxies can be informed of this fact by adding "Vary: Accept" to the response headers. Otherwise WebP data may be served to browsers that do not support it, for example in the following scenario:
 * A browser that supports WebP requests the JPG. The optimizer re-encodes it to WebP. The proxy caches the WebP data.
 * After this another browser that doesn't support WebP requests the JPG. The proxy sends the WebP data to the browser.

- [x] Integration tests added
- [x] Make sure the linting passes

* Fix using-preact example deps (vercel#26821)

Fix after vercel#26133

* Add additional tests for image type detection (vercel#26832)

Adding additional tests. Follow up to vercel#26705

* Fix immutable header for image with static import & unoptimized (vercel#26836)

Fixes vercel#26587

* Update `publish-canary` script to include checkout (vercel#26840)

* Update `publish-canary` script to include checkout

* Update contrib with publishing section

* v11.0.2-canary.4

* Make sure 404 pages do not get cached by a CDN when using next start (vercel#24983)

Co-authored-by: Jiachi Liu <inbox@huozhi.im>
Co-authored-by: JJ Kasper <jj@jjsweb.site>

* Update to environment-variable.md (vercel#26863)



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [x] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes

## Why the change
I lost quite a few hours figuring out why my environment variable was `undefined` in the browser.
I read about the built-in support and was like: "Oh nice" and didn't read much further. I missed the part about how you need to prefix your variables with `NEXT_PUBLIC_` in order to expose them to the browser.
I think a hint to this in the anchor link to that section will make it more discoverable as it's then mentioned near the top and will save people who are like me some time and a headache.

* Don't emit duplicate image files (vercel#26843)

fixes vercel#26607

This change makes it so the image loader plugin only emits a file while processing an image import for the client. The final generated image URL was already the same in SSR and CSR anyway, so this change doesn't have any functional impact.

I also changed the name of the static page in the image component tests, since it was causing some conflicts with the static assets folder.

* Add instructions on how to add nextjs.org/docs/messages urls (vercel#26865)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* Rename example folder to with-notion

* Update references of example

* Reorder docs manifest and rename to Script Optimization. (vercel#26874)

So there's _conformance_ between the other docs / optimizations.

* Fix typo on "occured" to "occurred" (vercel#26876)

- Fix typo on "occured" to "occurred"

* Update README

Co-authored-by: Sam Robbins <samrobbinsgb@gmail.com>
Co-authored-by: Jiachi Liu <inbox@huozhi.im>
Co-authored-by: Peter Mekhaeil <4616064+petermekhaeil@users.noreply.github.com>
Co-authored-by: Rob Vermeer <rob@vermeertech.nl>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
Co-authored-by: Brandon Bayer <b@bayer.ws>
Co-authored-by: Alex Castle <atcastle@gmail.com>
Co-authored-by: Vitaly Baev <ping@baev.dev>
Co-authored-by: Lee Robinson <me@leerob.io>
Co-authored-by: destruc7i0n <6181960+destruc7i0n@users.noreply.github.com>
Co-authored-by: Steven <steven@ceriously.com>
Co-authored-by: Joshua Byrd <phocks@gmail.com>
Co-authored-by: Pranav P <pranavkp.me@outlook.com>
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
Co-authored-by: John <john@rackles.io>
Co-authored-by: Tim Neutkens <timneutkens@me.com>
Co-authored-by: Vadorequest <ambroise.dhenain@gmail.com>
Co-authored-by: hiro <hiro0218@gmail.com>
Co-authored-by: Houssein Djirdeh <houssein@google.com>
Co-authored-by: Soham Shah <47717492+sohamsshah@users.noreply.github.com>
Co-authored-by: Gerald Monaco <gbmonaco@google.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Nils Schönwald <nils@schoen.world>
Co-authored-by: D. Kasi Pavan Kumar <44864604+kasipavankumar@users.noreply.github.com>
Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
Co-authored-by: Joachim Viide <jviide@iki.fi>
Co-authored-by: Artur Sedlukha <sedlukha@icloud.com>
Co-authored-by: Paul van den Dool <paulvddool@msn.com>
Co-authored-by: hiro <hiroyuki.kikuchi@zozo.com>
flybayer pushed a commit to blitz-js/next.js that referenced this issue Aug 19, 2021
Partially solves vercel#26539 by adding back the log output when a config file is used



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes
@ssylvia
Copy link

ssylvia commented Sep 8, 2021

Just following up on this ticket. Looks like my specific issue is that next v11 is not respecting the babelrcRoots defined in the custom babel config: #28934

@jasonwilliams
Copy link

#29500 is also affected by the babel loader change

@styfle styfle modified the milestones: 11.1.x, 12.0.4 Nov 5, 2021
@timneutkens timneutkens removed this from the 12.0.5 milestone Nov 17, 2021
@timneutkens timneutkens added the Webpack Related to Webpack with Next.js. label Nov 17, 2021
@RavenHursT
Copy link

I'm running into this w/ NextJS 12

I have a .babelrc.js file in the root of my project:

console.log('WTF??')
module.exports = {
  "env": {
    "development": {
      "plugins": [
        [
          "foo",
          {
            "ssr": true,
            "minify": true,
            "transpileTemplateLiterals": true,
            "pure": true,
            "displayName": true,
            "preprocess": false
          }
        ]
      ],
      "presets": ["next/babel"]
    },
    "production": {
      "plugins": [
        [
          "foo",
          {
            "ssr": true,
            "minify": true,
            "transpileTemplateLiterals": true,
            "pure": true,
            "displayName": true,
            "preprocess": false
          }
        ]
      ],
      "presets": ["next/babel"]
    }
  },
  "plugins": [
    [
      "foo",
      {
        "ssr": true,
        "minify": true,
        "transpileTemplateLiterals": true,
        "pure": true,
        "displayName": true,
        "preprocess": false
      }
    ]
  ],
  "presets": ["next/babel"]
}

When I run next build/src I see the WTF?? console log, but as you can see, I've replaced all the plug names w/ "foo".

Shouldn't the build fail when babel cannot find a plugin module by the given name??

Seems like the file's being read, but the exported config isn't actually being applied to babel upon build

@brianmorin-ef
Copy link

I was running into what I think was the same problem on v12 with custom server. I added an empty-ish file called babel.config.js into my ./src directory and it's causing my real babel config to get picked up in the root. So the key was to have a config file in both places but put the actual configuring into the root.

In my custom server: const app = next({ dir: "./src", dev: isDev });

My root babel.config.js is my actual config filled in with stuff about emotion, etc.

src/babel.config.js:

module.exports = {};

@dhay
Copy link

dhay commented Jan 6, 2022

We just upgraded to Next 12 and had to do something similar to @brianmorin-ef . We also have a custom server that sets the dir to 'src'

const nextApp = next({ dev, dir: 'src' });

However, we had to do something different with our babel config. We kept the original configuration file in the root directory (e.g. .babelrc.config.js) and then created the following file: src/babel.config.js with the contents:

module.exports = require('../.babelrc.js');

I know the direction is to use SWC instead of babel, but in the meantime, it seems like there might be a regression in the way bable configuration is detected and evaluated.

@samcx samcx added bug Issue was opened via the bug report template. and removed kind: bug labels Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Webpack Related to Webpack with Next.js.
Projects
None yet
Development

No branches or pull requests