Here's my code:
// lib/test2.ts
export function test2() {
console.log("test2");
}
// pages/index.tsx
import { GetServerSideProps } from "next";
// works
import { test } from "../lib/test.js";
// error
import { test2 } from "../lib/test2.js";
export const getServerSideProps: GetServerSideProps = async ({
req,
}): Promise<{ props: {} }> => {
test();
test2();
return { props: {} };
};
export default function Home(props: {}) {
return <div>Hi</div>;
}
When I run this code, I get
Module not found: Can't resolve '../lib/test2.js' in '/Users/USER/Documents/software/nextjs-test/pages'
I'm not sure why. Shouldn't lib/test2.ts compile to lib/test2.js, and the import should be fine? I suppose I'm not very familiar with how the imports actually get resolved when TypeScript is in the mix.
Link to all the code here: https://github.com/arcticmatt/nextjs-test