Typescript file import issue
Unanswered
Red wood ant posted this in #help-forum
Red wood antOP
Hello there.
I have this issue importing a file out of the main directory where nextjs is (meaning I import as "../../shared"). I get the error shown in the screenshot.
The strange thing is, when I move the file inside the nextjs dir, there's no issue with it and it works as normal.
For context, we're using connectrpc, and types from the backend code (with is go) are generated in a shared directory. We already have a react project setup that reads them correctly, but we're trying to switch it over to nextjs, and it seems to have issues importing it when it's not in the same directory (or subdir) as the root directory of the project.
Any help is appreciated, and if any other details are required, let me know.
I have this issue importing a file out of the main directory where nextjs is (meaning I import as "../../shared"). I get the error shown in the screenshot.
The strange thing is, when I move the file inside the nextjs dir, there's no issue with it and it works as normal.
For context, we're using connectrpc, and types from the backend code (with is go) are generated in a shared directory. We already have a react project setup that reads them correctly, but we're trying to switch it over to nextjs, and it seems to have issues importing it when it's not in the same directory (or subdir) as the root directory of the project.
Any help is appreciated, and if any other details are required, let me know.
1 Reply
Red wood antOP
// has no issues
import { PublicProfileService } from "../gen/connectrpc/eliza/v1/profile_connect";
// source of error
import { PublicProfileService as SharedPublicProfileService } from "../../shared/ts/connect/galatea/v1/profile_connect";
export const getServerSideProps = async () => {
const transport = createConnectTransport({
// Note: you cannot use a relative path like `/api` here because SSR requires absolute URLs.
baseUrl: "http://localhost:8080",
});
// this works
const profileClient = createPromiseClient(PublicProfileService, transport);
// this is prevented from working
const sharedProfileClient = createPromiseClient(
SharedPublicProfileService,
transport,
);
return {
props: {
response: response.toJson(),
},
};
};For further context, this is what the code looks like