Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Convert alias path imports to relative imports #950

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

riffbyte
Copy link

This fixes the issue with built typescript artifacts throwing "Cannot find module 'src/types' or its corresponding type declarations" errors.
See #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

This fixes the issue with built typescript artifacts throwing "Cannot find module 'src/types' or its corresponding type declarations" errors.
See garmeeh#942
@garmeeh
Copy link
Owner

garmeeh commented Jul 20, 2022

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.

@riffbyte
Copy link
Author

riffbyte commented Aug 8, 2022

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

@kristian240
Copy link

@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"]
}

@ajmnz
Copy link

ajmnz commented Aug 23, 2022

@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[].

See the reproduction CodeSandbox

@LiamMyles
Copy link

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

@pfernandom
Copy link

+1 this is breaking for me too

@indicozy
Copy link

+1, just bumping here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants