未验证 提交 fc98c13a 编写于 作者: J Joe Haddad 提交者: GitHub

Warn on duplicate Sass deps (#16398)

Fixes #13953
上级 3dec5000
# Duplicate Sass Dependencies
#### Why This Error Occurred
Your project has a direct dependency on both `sass` and `node-sass`, two
different package that both compile Sass files!
Next.js will only use one of these, so it is suggested you remove one or the
other.
#### Possible Ways to Fix It
The `sass` package is a modern implementation of Sass in JavaScript that
supports all the new features and does not require any native dependencies.
Since `sass` is now the canonical implementation, we suggest removing the older
`node-sass` package, which should speed up your builds and project install time.
**Via npm**
```bash
npm uninstall node-sass
```
**Via Yarn**
```bash
yarn remove node-sass
```
### Useful Links
- [`sass` package documentation](https://github.com/sass/dart-sass)
......@@ -91,6 +91,18 @@ const nextDev: cliCommand = (argv) => {
)
}
}
const [sassVersion, nodeSassVersion] = await Promise.all([
getPackageVersion({ cwd: dir, name: 'sass' }),
getPackageVersion({ cwd: dir, name: 'node-sass' }),
])
if (sassVersion && nodeSassVersion) {
Log.warn(
'Your project has both `sass` and `node-sass` installed as dependencies, but should only use one or the other. ' +
'Please remove the `node-sass` dependency from your project. ' +
' Read more: https://err.sh/next.js/duplicate-sass'
)
}
}
const port = args['--port'] || 3000
......
{
"dependencies": {
"node-sass": "*",
"sass": "*"
}
}
export default function Home() {
return <p>Hello</p>
}
......@@ -18,6 +18,7 @@ const dirOldReact = join(__dirname, '../old-react')
const dirOldReactDom = join(__dirname, '../old-react-dom')
const dirExperimentalReact = join(__dirname, '../experimental-react')
const dirExperimentalReactDom = join(__dirname, '../experimental-react-dom')
const dirDuplicateSass = join(__dirname, '../duplicate-sass')
describe('CLI Usage', () => {
describe('no command', () => {
......@@ -295,6 +296,22 @@ describe('CLI Usage', () => {
await killApp(instance)
})
test('duplicate sass deps', async () => {
const port = await findPort()
let stderr = ''
let instance = await launchApp(dirDuplicateSass, port, {
stderr: true,
onStderr(msg) {
stderr += msg
},
})
expect(stderr).toMatch('both `sass` and `node-sass` installed')
await killApp(instance)
})
})
describe('export', () => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册