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

Build errors when project contains a symlink #8238

Closed
acifani opened this issue Aug 4, 2019 · 7 comments
Closed

Build errors when project contains a symlink #8238

acifani opened this issue Aug 4, 2019 · 7 comments

Comments

@acifani
Copy link
Contributor

acifani commented Aug 4, 2019

Bug report

Describe the bug

Next commands build and dev error out whenever there is a symbolic link in a directory within the project

To Reproduce

Either

Expected behavior

Build should not error out, whether or not it should follow the symlink I don't know

Screenshots

Error output:

❯ npm run build

> [email protected] build /path/to/repo/next-symlink-bug
> next build

> Build error occurred
{ [Error: ENOENT: no such file or directory, stat '/path/to/repo/next-symlink-bug/some_dir/some_symlink']
  errno: -2,
  code: 'ENOENT',
  syscall: 'stat',
  path:
   '/path/to/repo/next-symlink-bug/some_dir/some_symlink' }

System information

  • OS: macOS 10.14.5
  • Version of Next.js: ^9

Additional context

The exception is caused by the build checking for possible TypeScript files. More specifically, by fs.statSync in this line. There's a separate command, fs.symlinkLink, available for symlinks

@acifani
Copy link
Contributor Author

acifani commented Oct 5, 2019

Fixed recently 👍

@acifani acifani closed this as completed Oct 5, 2019
@reflash
Copy link

reflash commented Jun 18, 2020

Same appears to happen when I have a symlink to a folder:

Error! ENOENT: no such file or directory, stat '/home/runner/work/<projname>/<projname>/<symlink>

@kjmph
Copy link

kjmph commented Oct 28, 2020

This still happens to me with broken links.

For instance:

host:next.js kjmph$ ln -s notexists examples/basic-css/pages/testfile
host:next.js kjmph$ yarn next ./examples/basic-css/
yarn run v1.22.10
$ node --trace-deprecation packages/next/dist/bin/next ./examples/basic-css/
ready - started server on http://localhost:3000
[Error: ENOENT: no such file or directory, stat '/home/kjmph/next.js/examples/basic-css/pages/testfile'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'stat',
  path: '/home/kjmph/next.js/examples/basic-css/pages/testfile'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@quantizor
Copy link
Contributor

@acifani this should be reopened

@MaxiSantos
Copy link

in your next.config.js add this

const { i18n } = require('./next-i18next.config');

module.exports = {
  ...
  webpack: (config, { buildId, dev }) => {
    config.resolve.symlinks = false
    return config
  }
}

@kjmph
Copy link

kjmph commented Jan 27, 2022

Before this gets locked and unable to comment, like #15278, disabling symlinks isn't always appropriate. I believe pnpm uses them extensively, plus, new versions of Next.js use SWC extensively, and webpack isn't even installed with latest (v12.0.9 at this time).

The problem with broken links and emacs lock files is this code:

const stats = await promises.stat(absolutePath)
isDirectory = stats.isDirectory()

When a symlink is encountered, recursiveReadDir tries and stat the file. This can lead to ENOENT exceptions. Either all callers of this function should pass in configurable parameters for the ignore RegExp. Which is unlikely, see here:

const typescriptFiles = await recursiveReadDir(
pagesDir,
/.*\.(ts|tsx)$/,
/(node_modules|.*\.d\.ts)/
)

Or!!! recursiveReadDir should gobble those ENOENT exceptions and let us move along in the build. Please don't kill this thread too.

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants