next-seo
next-seo copied to clipboard
Chore: Convert alias path imports to relative imports
This fixes the issue with built typescript artifacts throwing "Cannot find module 'src/types' or its corresponding type declarations" errors. See https://github.com/garmeeh/next-seo/issues/942
Description of Change(s):
- Replaced all of the aliased
src/*
imports with relative imports.
https://github.com/garmeeh/next-seo/blob/master/CONTRIBUTING.md
Hey @oleg-semyonov sorry about the delay. (a long one 😟)
Could you give me an example of file that this is happening with? I use next-seo on all of my projects and haven't had an issue so wondering is it a specific component giving some trouble.
Hey @garmeeh, sorry for long reply as well, somehow missed the notification 😕
The project that's having the issues is this one: https://github.com/prezly/theme-kit-nextjs
And here is an example of a component that uses next-seo
.
I silenced the errors by setting skipLibCheck
to true
in the tsconfig.
Just today I tried removing the rule, but the errors are still there when I build the library. I've got the latest version (5.5.0) installed.
Here's a link to project's tsconfig.json.
The project is build with just the tsc
compiler and compiled to CommonJS.
Here are just some of many errors I get from next-seo
when building:
![image](https://user-images.githubusercontent.com/1641218/183353863-d079a04f-791c-47b8-8c26-1ede43766e3b.png)
@garmeeh @oleg-semyonov I have the same issue on my end and I cannot update the next-seo
for a while now. Any news on when or how to resolve this?
// tsconfig
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": true,
"skipLibCheck": false,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"allowUnreachableCode": false,
"alwaysStrict": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
"allowUnusedLabels": false,
"declaration": true,
"experimentalDecorators": true,
"inlineSources": true,
"noImplicitAny": false,
"noImplicitReturns": true,
"noUnusedParameters": true,
"sourceMap": true,
"strictFunctionTypes": false,
"baseUrl": ".",
"incremental": true,
"paths": {
"@/*": ["src/*"]
}
},
"include": ["./common.d.ts", "./src", "./jest-setup.ts", "middleware.ts"],
"exclude": ["node_modules", "bin"]
}
@garmeeh 👋🏼
Any news on this one? Basically what's happening is that TypeScript is unable to resolve absolute imports pointing to, for example, src/types
.
You can find an example on [email protected]
if you take a look at node_modules/next-seo/lib/jsonld/product.d.ts
. All types from the following import import type { Review, AggregateRating, AggregateOffer, Offers } from 'src/types';
are unresolved, since there's no such thing as src/types
– it should be ../types
This causes components like ProductJsonLd
to have properties such as reviews
to act like if their type was any[]
.
Just a quick message to bump this, as I think this fix might also resolve an issue I'm facing where the type checking for FAQ questions isn't working because src/type
doesn't resolve. Below is the type declaration for FAQPageJsonLd
found in node_modules/next-seo/lib/jsonld/faqPage.d.ts
which seems to be causing the problem.
import type { Question } from 'src/types';
import { JsonLdProps } from './jsonld';
export interface FAQPageJsonLdProps extends JsonLdProps {
mainEntity: Question[];
}
declare function FAQPageJsonLd({ type, keyOverride, mainEntity, ...rest }: FAQPageJsonLdProps): JSX.Element;
export default FAQPageJsonLd;
I'm using "next-seo": "^5.5.0"
FYI
+1 this is breaking for me too
+1, just bumping here