question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Next 11.0.1 forces wrong line-endings on Windows in next-env.d.ts

See original GitHub issue

What version of Next.js are you using?

@latest v11.0.1

What version of Node.js are you using?

@latest-ish v15.14.0

What browser are you using?

Chrome

What operating system are you using?

Windows 10 x64

How are you deploying your application?

Vercel

Describe the Bug

Next 11 writes next-env.d.ts all the time, but it uses *nix style line endings: image image

Expected Behavior

*Don’t manually force line-endings to CR *Respect .gitattributes file (explictly specificing CR LF) *Respect operating-system preference (CR LF on Windows)

To Reproduce

  1. Throw Prettier errors using this configuration:

prettier.config.js

module.exports = {
  // These settings are handled in .editorconfig:
  tabWidth: 2, // indent_size = 2
  useTabs: false, // indent_style = space
  endOfLine: "lf", // end_of_line = lf
  semi: false, // default: true
  singleQuote: false,
  printWidth: 80,
  trailingComma: "es5",
  bracketSpacing: true,
}

.eslintrc.js

module.exports = {
  extends: [
    "eslint:recommended",
    "plugin:prettier/recommended",
  ],
  rules: {
    "prettier/prettier": "error",
  },
}

Preferable solution: Ask some of your engineers to switch to Windows full-time

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:10
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
ijjkcommented, Sep 20, 2021

Hi, this has been updated in v11.1.3-canary.25 of Next.js, please update and give it a try!

1reaction
DoctorDerekcommented, Jul 27, 2021

@thadeucity In my projects I use .editorconfig, prettier.config.js, and .gitattributes to all force LF, because otherwise ESLint will error on CR/LF line ending with the setting prettier/prettier: "error".

The .editorconfig will force LF on file save in VS Code (while the Prettier VS code extension will not), but the files will still get cloned down with CRLF and all have errors (until running eslint --fix . or prettier --write .) without the .gitattributes file.

(For anyone else having this issue, I posted a thorough discussion of it over in @tailwindlabs/tailwindcss#3760.)

For this .next-env.d.ts bug on Windows, here’s the relevant code using os.EOL.

@packages/next/lib/typescript/writeAppTypeDeclarations.ts: https://github.com/vercel/next.js/blob/26105e285de056ff59ea3597a4b2d1293f82b5cf/packages/next/lib/typescript/writeAppTypeDeclarations.ts#L1-L27

To fix this, I guess the system would have to query the Prettier.config.js (or other named files, i.e. by importing prettier if found and using its configuration file as is done here: https://github.com/prettier/prettier-eslint/blob/c62769ef430749fb9650c7e1d05f5cf7442a48a2/src/index.js#L255-L263

This would seem to start becoming quite a difficult problem, though, since line endings can be set in .editorconfig, prettier.config.js, .prettierrc, .eslintrc (not recommended due to compatibility issues with VS Code Prettier extension), etc., not to mention .gitattributes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Detect line endings in next-env.d.ts #27039 - GitHub
If a developer on a Windows machine uses a file committed by a developer on a Mac for instance, this causes an unnecessary...
Read more >
Force LF line ending on auto generated file next-env.d.ts on ...
The file is auto generated by Next.js. Webstorm on Windows 10. Line separator in Settings > Editor > Code Style is set to...
Read more >
How to force consistent line endings in Git commits with cross ...
Q1 Enforcing consistent lineendings. Q2 Enforcing at commit as well as checkout (comment). I'll divide this into 2 parts: Practice and ...
Read more >
jest-runtime | Yarn - Package Manager
Jest will set process.env.NODE_ENV to 'test' if it's not set to something else. You can use that in your configuration to conditionally setup...
Read more >
Next.js 12 - Hacker News
I'm building a custom server (which hopefully now can be replaced with middleware?) which I build with tsc: $ tsc --strict --esModuleInterop -- ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found