Typescript errors for missing `@babel/core` and `@babel/traverse` types when using `@linaria/tags` and `@linaria/utils`
Environment
- Linaria version:
- @linaria/core:
4.2.9 - @linaria/tags:
4.3.5 - @linaria/utils:
4.3.4
- @linaria/core:
- Bundler (+ version): Typescript
4.7.4 - Node.js version:
v18.16.0 - OS: Windows & Ubuntu
Description
When using @linaria/tags and @linaria/utils as dependency (in my case actually as dependency of a dependency) in a Typescript project, the following errors are emitted:
node_modules/@linaria/tags/types/BaseProcessor.d.ts:1:33 - error TS7016: Could not find a declaration file for module '@babel/core'. 'C:/my/app/node_modules/@babel/core/lib/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/babel__core` if it exists or add a new declaration (.d.ts) file containing `declare module '@babel/core';`
1 import type { types as t } from '@babel/core';
~~~~~~~~~~~~~
node_modules/@linaria/tags/types/utils/types.d.ts:1:39 - error TS7016: Could not find a declaration file for module '@babel/core'. 'C:/my/app/node_modules/@babel/core/lib/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/babel__core` if it exists or add a new declaration (.d.ts) file containing `declare module '@babel/core';`
1 import type { TransformOptions } from '@babel/core';
~~~~~~~~~~~~~
node_modules/@linaria/utils/types/babel.d.ts:1:23 - error TS7016: Could not find a declaration file for module '@babel/core'. 'C:/my/app/node_modules/@babel/core/lib/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/babel__core` if it exists or add a new declaration (.d.ts) file containing `declare module '@babel/core';`
1 import type core from '@babel/core';
~~~~~~~~~~~~~
node_modules/@linaria/utils/types/collectExportsAndImports.d.ts:1:31 - error TS7016: Could not find a declaration file for module '@babel/traverse'. 'C:/my/app/node_modules/@babel/traverse/lib/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/babel__traverse` if it exists or add a new declaration (.d.ts) file containing `declare module '@babel/traverse';`
1 import type { NodePath } from '@babel/traverse';
~~~~~~~~~~~~~~~~~
node_modules/@linaria/utils/types/findIdentifiers.d.ts:1:31 - error TS7016: Could not find a declaration file for module '@babel/traverse'. 'C:/my/app/node_modules/@babel/traverse/lib/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/babel__traverse` if it exists or add a new declaration (.d.ts) file containing `declare module '@babel/traverse';`
1 import type { NodePath } from '@babel/traverse';
~~~~~~~~~~~~~~~~~
node_modules/@linaria/utils/types/isExports.d.ts:1:31 - error TS7016: Could not find a declaration file for module '@babel/traverse'. 'C:/my/app/node_modules/@babel/traverse/lib/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/babel__traverse` if it exists or add a new declaration (.d.ts) file containing `declare module '@babel/traverse';`
1 import type { NodePath } from '@babel/traverse';
~~~~~~~~~~~~~~~~~
node_modules/@linaria/utils/types/isRemoved.d.ts:1:31 - error TS7016: Could not find a declaration file for module '@babel/traverse'. 'C:/my/app/node_modules/@babel/traverse/lib/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/babel__traverse` if it exists or add a new declaration (.d.ts) file containing `declare module '@babel/traverse';`
1 import type { NodePath } from '@babel/traverse';
~~~~~~~~~~~~~~~~~
node_modules/@linaria/utils/types/isRequire.d.ts:1:31 - error TS7016: Could not find a declaration file for module '@babel/traverse'. 'C:/my/app/node_modules/@babel/traverse/lib/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/babel__traverse` if it exists or add a new declaration (.d.ts) file containing `declare module '@babel/traverse';`
1 import type { NodePath } from '@babel/traverse';
~~~~~~~~~~~~~~~~~
node_modules/@linaria/utils/types/isTypedNode.d.ts:1:31 - error TS7016: Could not find a declaration file for module '@babel/traverse'. 'C:/my/app/node_modules/@babel/traverse/lib/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/babel__traverse` if it exists or add a new declaration (.d.ts) file containing `declare module '@babel/traverse';`
1 import type { NodePath } from '@babel/traverse';
~~~~~~~~~~~~~~~~~
node_modules/@linaria/utils/types/isUnnecessaryReactCall.d.ts:1:31 - error TS7016: Could not find a declaration file for module '@babel/core'. 'C:/my/app/node_modules/@babel/core/lib/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/babel__core` if it exists or add a new declaration (.d.ts) file containing `declare module '@babel/core';`
1 import type { NodePath } from '@babel/core';
~~~~~~~~~~~~~
node_modules/@linaria/utils/types/options/buildOptions.d.ts:1:39 - error TS7016: Could not find a declaration file for module '@babel/core'. 'C:/my/app/node_modules/@babel/core/lib/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/babel__core` if it exists or add a new declaration (.d.ts) file containing `declare module '@babel/core';`
1 import type { TransformOptions } from '@babel/core';
~~~~~~~~~~~~~
node_modules/@linaria/utils/types/options/loadBabelOptions.d.ts:1:39 - error TS7016: Could not find a declaration file for module '@babel/core'. 'C:/my/app/node_modules/@babel/core/lib/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/babel__core` if it exists or add a new declaration (.d.ts) file containing `declare module '@babel/core';`
1 import type { TransformOptions } from '@babel/core';
~~~~~~~~~~~~~
node_modules/@linaria/utils/types/options/types.d.ts:1:39 - error TS7016: Could not find a declaration file for module '@babel/core'. 'C:/my/app/node_modules/@babel/core/lib/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/babel__core` if it exists or add a new declaration (.d.ts) file containing `declare module '@babel/core';`
1 import type { TransformOptions } from '@babel/core';
~~~~~~~~~~~~~
node_modules/@linaria/utils/types/scopeHelpers.d.ts:1:40 - error TS7016: Could not find a declaration file for module '@babel/traverse'. 'C:/my/app/node_modules/@babel/traverse/lib/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/babel__traverse` if it exists or add a new declaration (.d.ts) file containing `declare module '@babel/traverse';`
1 import type { Binding, NodePath } from '@babel/traverse';
~~~~~~~~~~~~~~~~~
node_modules/@linaria/utils/types/visitors/JSXElementsRemover.d.ts:1:31 - error TS7016: Could not find a declaration file for module '@babel/traverse'. 'C:/my/app/node_modules/@babel/traverse/lib/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/babel__traverse` if it exists or add a new declaration (.d.ts) file containing `declare module '@babel/traverse';`
1 import type { NodePath } from '@babel/traverse';
Installing the @types/babel__core and @types/babel__traverse types to my project solves the issue and therefore might be a solution but I am wondering if it's the correct way because:
-
@linaria/tagsand@linaria/corespecifies these types as devDependencies https://github.com/callstack/linaria/blob/bb80386f5cfa34af5343495d244d8044e54cf666/packages/tags/package.json#L41 and https://github.com/callstack/linaria/blob/bb80386f5cfa34af5343495d244d8044e54cf666/packages/core/package.json#L68 which should mean they are only relevant at build time for these projects. If they are required when consuming these libraries (also during build time of my project), I think@types/babel__coreand@types/babel__traverseshould be a peerDependency for@linaria/tagsand@linaria/coreas they will then (npm >= 7) be installed automatically in the correct version. - I would always have to match the version for these types to the ones that the @linaria packages use
- I could not find some hint that installing these types is required.
=> Overall I think these types should be peerDependencies for these packages if they are required when using these libraries in a TS project.
Reproducible Demo
See this issue https://github.com/remirror/remirror/issues/2064 and this repository with a reproduction: https://github.com/DRichter-r/remirrorlibcheck
The demo code in this repo uses remirror that internally depends on @linaria/tags and @linaria/core and therefore causes these errors.