next.js icon indicating copy to clipboard operation
next.js copied to clipboard

Cannot use import alias if route path starts with period

Open jdhenry08 opened this issue 1 year ago • 2 comments

Link to the code that reproduces this issue

https://github.com/jdhenry08/next-route-broken-imports

To Reproduce

  1. View src/app/.well-known/route.ts
  2. Change "../../constants" import to "~/constants" or "src/constants"

Current vs. Expected behavior

Importing the constants file from either of those two paths should work, since they're aliased in tsconfig.json, but the red squiggly remains :(

Provide environment information

Node: 20.9.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.10.2
Relevant Packages:
  next: 14.2.5 // Latest available version is detected (14.2.5).
  eslint-config-next: N/A
  react: 18.3.1
  react-dom: 18.3.1
  typescript: N/A
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Not sure

Which stage(s) are affected? (Select all that apply)

Other (Deployed)

Additional context

No response

jdhenry08 avatar Aug 19 '24 19:08 jdhenry08

This is due to tsconfig ignoring hidden files (anything that starts with a dot).

You can get around this by adding the folder to the include path in tsconfig.json:

"include": [
  "src/app/.well-known/**/*"
]

simonri avatar Aug 24 '24 17:08 simonri

Ah, yup - that did the trick!

Might I suggest that the documentation for setting up the Vercel toolbar/feature flags be updated to mention something along these lines, given that it uses a similar route? Not sure what the right repo is to make that suggestion.

jdhenry08 avatar Aug 26 '24 14:08 jdhenry08