I try to build app on server using next build command and it faild to compile with error
Module not found: Can't resolve 'next/Link' in '...components/Footer'
Problem is, this only happens on server. When I try to build it on local machine it works ok.
next.config.js
const withSass = require('@zeit/next-sass');
const withCSS = require('@zeit/next-css');
const path = require('path');
module.exports = withCSS(withSass({
webpack (config) {
config.resolve.alias['~'] = path.join(__dirname)
return config;
}
}));
components/Footer.js
import React, { Component } from 'react'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import Link from 'next/Link'
import './Footer.scss'
class Footer extends Component{
render () {
return (
<footer>
<div className="links">
<Link href="/object/jkhArena">
<a>
<div className="item">
some text
</div>
</a>
</Link>
<Link href="/object/jkhDvizhenie">
<a>
<div className="item">
some text
</div>
</a>
</Link>
<Link href="/">
<a>
<div className="item">
some text
</div>
</a>
</Link>
</div>
</footer>
)
}
}
export default Footer
components/Layout.js
import Footer from '~/components/Footer/Footer'
const Layout = props => {
return (
<div>
<Header />
{props.children}
<Footer />
</div>
);
};
export default Layout
Build app for using on prodaction
The import should be import NextLink from 'next/link';
(lowercase link
).
If you local machine is a Mac then the filesystem is not case-sensitive whereas Linux is.
It's work. Ty.
Hi, I got this error too, run on localhost very well but deploy it down
Check the sentence casing of your module imports.
Hi, I got this error too, run on localhost very well but deploy it down
Hi, I got this error too, run on localhost very well but deploy it down
Hi, i have the same error on build the next app
Try changing the name of the file completely and test again. There can be case sensitivity issues with git and operating systems, especially if you commit a file as one case (i.e. componentOne.js
) and then change it later (to something like ComponentOne.js
).
If that works, commit that new file name and then you can change it back to the original filename and commit that again.
Change your filenames and directories to your desired case, fix your imports to match the new case changes, verify that the app builds locally, and then use the following command to tell git to recognize your case changes:
git config core.ignorecase false
Then, push your changes to your remote origin.
Most helpful comment
The import should be
import NextLink from 'next/link';
(lowercaselink
).If you local machine is a Mac then the filesystem is not case-sensitive whereas Linux is.