Next.js: Module not found: Can't resolve 'next/Link' in '...components/Footer'

Created on 21 Nov 2019  路  7Comments  路  Source: vercel/next.js

Bug report

Describe the bug

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

Expected behavior

Build app for using on prodaction

Screenshots

nextjs

nextjs2

Server system information

  • OS: Ubuntu 18.04
  • Version of Next.js: 9.1.3
  • Version of Node: 12.13.1

Most helpful comment

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.

All 7 comments

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

image
image

Check the sentence casing of your module imports.

Hi, I got this error too, run on localhost very well but deploy it down

image
image

Hi, I got this error too, run on localhost very well but deploy it down

image
image

Hi, i have the same error on build the next app

Captura de pantalla -2020-05-05 09-20-31

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jesselee34 picture jesselee34  路  3Comments

pie6k picture pie6k  路  3Comments

timneutkens picture timneutkens  路  3Comments

flybayer picture flybayer  路  3Comments

ghost picture ghost  路  3Comments