You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Run next info (available from version 12.0.8 and up)
$ npx --no-install next --version
Next.js v12.0.7
What version of Next.js are you using?
12.0.7
What version of Node.js are you using?
16.13.1
What browser are you using?
n/a
What operating system are you using?
Windows
How are you deploying your application?
n/a
Describe the Bug
When importing a TypeScript file using a .js file extension, Next fails with "Module not found"
$ npm run build
> build
> next build
info - Checking validity of types...
info - Creating an optimized production build...
Failed to compile.
./pages/index.tsx
Module not found: Can't resolve '../lib/helper.js' in 'C:\Users\james\dev\foobar\pages'
> Build failed because of webpack errors
Expected Behavior
Next.js should resolve TypeScript imports. TypeScript recommends using the .js file extension to import TypeScript files:
No workarounds - other than changing the import to .ts or removing the extension. Which then breaks other things that expect the .js extension. Not a good situation.
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
vercel
locked as resolved and limited conversation to collaborators
Feb 17, 2022
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Run
next info
(available from version 12.0.8 and up)What version of Next.js are you using?
12.0.7
What version of Node.js are you using?
16.13.1
What browser are you using?
n/a
What operating system are you using?
Windows
How are you deploying your application?
n/a
Describe the Bug
When importing a TypeScript file using a
.js
file extension, Next fails with "Module not found"Expected Behavior
Next.js should resolve TypeScript imports. TypeScript recommends using the
.js
file extension to import TypeScript files:My Next.js application is not an isolated project; it shares TypeScript modules with other environments that rely on this
.js
file extension.To Reproduce
echo 'export const n = 5' > lib/helper.ts
pages/index.tsx
, add:import {n} from '../lib/helper.js'
next build
ornext dev
The text was updated successfully, but these errors were encountered: