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:
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
- In
pages/index.tsx, add: import {n} from '../lib/helper.js'
- Run
next build or next dev