My project's setup is tsdx
(based on Rollup
and Typescript
).
Working in my IDE (vscode) everything looks fine, and even running yarn tsc
works without errors.
When I'm running yarn build
(which is tsdx build
) I get the following error:
(typescript) Error: /home/me/dev/app/src/components/alert/Alert.tsx(36,7): semantic error TS2742: The inferred type of 'AlertContainer' cannot be named without a reference to '@emotion/serialize/node_modules/csstype'. This is likely not portable. A type annotation is necessary.
Error: /home/me/dev/app/src/components/alert/Alert.tsx(36,7): semantic error TS2742: The inferred type of 'AlertContainer' cannot be named without a reference to '@emotion/serialize/node_modules/csstype'. This is likely not portable. A type annotation is necessary.
The code referenced in the error is:
type AlertContainerProps = {
theme: any
};
const AlertContainer = styled(animated.div)<AlertContainerProps>`
${(props) => props.theme.primaryView}
...
`;
...
type AlertContentProps = Pick<React.ComponentProps<typeof AlertContainer>, 'style'> & {
status?: string
};
What am I doing wrong? How can I fix it?
I tried this solution but it didn't work.
When running the script "build" in monorepo NestJS and NextJS I got this error:
Client side:
Server side:
Apparently the client-side error was caused by Typescript trying to import AppRouter as a function rather than as a type.
Adding the settings to the root tsconfig.json file helped solve the problem:
The solution to the problem is taken from here: https://lightrun.com/solutions/microsoft-typescript-the-inferred-type-of-x-cannot-be-named-without-a-reference-to-y-this-is-likely-not-portable-a/