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

Detect node sass and react version #13968

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions errors/correct-sass-dependency.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Correct sass dependency

#### Why This Error Occurred

You are using both _sass_ and _node-sass_ in your project.

#### Possible Ways to Fix It

Your dependencies should contain only one of both, preferably node-sass.

They should look like this

```js
"dependencies": {
"node-sass": "^4.14.1",
}
```

instead of this

```js
"dependencies": {
"node-sass": "^4.14.1",
"sass": "^1.26.8"
}
```

### Useful Links

- [Related issue](https://github.com/vercel/next.js/issues/6681)
24 changes: 24 additions & 0 deletions errors/minimum-react-version.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Minimum React version

#### Why This Error Occurred

The version of react you are using is older than 16.10.
Next.js requires React 16.10 or newer for Fast Refresh to work correctly.
On older versions, Next.js will fallback to full page reload every time.

Please, take in mind that in this case your dev experience would be suboptimal and unexpected behaviour may occour.

#### Possible Ways to Fix It

Be sure your React version is 16.10 or newer.

```js
"dependencies": {
"react": "16.10",
}
```

### Useful Links

- [fast-refresh](https://nextjs.org/blog/next-9-4#fast-refresh)
- [react-refresh](https://github.com/facebook/react/tree/master/packages/react-refresh)
20 changes: 20 additions & 0 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,26 @@ export default async function getBaseWebpackConfig(
resolvedBaseUrl = path.resolve(dir, jsConfig.compilerOptions.baseUrl)
}

if (isServer) {
Copy link
Member

@timneutkens timneutkens Jul 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check should exist in packages/next/cli/next-dev.ts

const packageJsonPath = path.resolve(dir, './package.json')
const packageJsonFile = parseJsonFile(packageJsonPath)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking the version of React in their package.json might not be comprehensive enough. They could have ^16.8.6 but if they did their initial installation recently then they might actually have 16.13.1 installed as their React version (due to the version using the ^ which will bump them to the next minor version released).

I think checking their installed dependencies might give you a bit more coverage:

const packagePath = require.resolve('react/package.json')
const { version } = require(packagePath)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted! Will change it!

const { dependencies } = packageJsonFile
if (dependencies['react']) {
const version = +dependencies['react'].substr(0, 5)
if (version < 16.1) {
console.warn(
'Next.js requires React 16.10 or newer for Fast Refresh to work correctly. https://err.sh/next.js/minimum-react-version'
)
}
}

if (dependencies['node-sass'] != null && dependencies['sass'] != null) {
console.warn(
'It is not recommended to use node-sass and sass together. https://err.sh/next.js/correct-sass-dependency'
)
}
}

const resolveConfig = {
// Disable .mjs for node_modules bundling
extensions: isServer
Expand Down