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

[bug]: typescript errors when building with pnpm #41

Open
innerdvations opened this issue Aug 14, 2024 · 6 comments
Open

[bug]: typescript errors when building with pnpm #41

innerdvations opened this issue Aug 14, 2024 · 6 comments
Labels
issue: bug Issue reporting a bug severity: medium If it breaks the basic use of the product but can be worked around

Comments

@innerdvations
Copy link
Collaborator

innerdvations commented Aug 14, 2024

What version of @strapi/sdk-plugin are you using?

@strapi/sdk-plugin 5.1.0
pnpm 9.1.0

What's Wrong?

Building a plugin with pnpm doesn't work

➜  myplugin5 pnpm run build

> [email protected] build /Users/ben/dev/strapi/myplugin5
> strapi-plugin build

✔ Verified package.json
✔ Created build context
Building type files:
   entries:
    – myplugin5/admin/src/index.ts ./admin/src/index.ts -> ./dist/admin/src/index.d.ts
    – myplugin5/server/src/index.ts ./server/src/index.ts -> ./dist/server/src/index.d.ts
[ERROR]  server/src/controllers/index.ts:3:1 - TS2742: The inferred type of 'default' cannot be named without a reference to '.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@strapi/types/dist/core'. This is likely not portable. A type annotation is necessary.
[ERROR]  server/src/index.ts:19:1 - TS2742: The inferred type of 'default' cannot be named without a reference to '.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@strapi/types/dist/core'. This is likely not portable. A type annotation is necessary.
[ERROR]  server/src/services/index.ts:3:1 - TS2742: The inferred type of 'default' cannot be named without a reference to '.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@strapi/types/dist/core'. This is likely not portable. A type annotation is necessary.
[ERROR]  server/src/controllers/index.ts:3:1 - TS2742: The inferred type of 'default' cannot be named without a reference to '.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@strapi/types/dist/core'. This is likely not portable. A type annotation is necessary.
[ERROR]  server/src/services/index.ts:3:1 - TS2742: The inferred type of 'default' cannot be named without a reference to '.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@strapi/types/dist/core'. This is likely not portable. A type annotation is necessary.
[ERROR]  server/src/index.ts:19:1 - TS2742: The inferred type of 'default' cannot be named without a reference to '.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@strapi/types/dist/core'. This is likely not portable. A type annotation is necessary.
[ERROR]  server/src/index.ts:19:1 - TS2742: The inferred type of 'default' cannot be named without a reference to '.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@strapi/types/dist/core'. This is likely not portable. A type annotation is necessary.
[ERROR]  server/src/index.ts:19:1 - TS2742: The inferred type of 'default' cannot be named without a reference to '.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@strapi/types/dist/core'. This is likely not portable. A type annotation is necessary.
[ERROR]  server/src/index.ts:19:1 - TS2742: The inferred type of 'default' cannot be named without a reference to '.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@strapi/types/dist/core'. This is likely not portable. A type annotation is necessary.
[ERROR]  server/src/index.ts:19:1 - TS2742: The inferred type of 'default' cannot be named without a reference to '.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@strapi/types/dist/core'. This is likely not portable. A type annotation is necessary.
[ERROR]  Failed to compile TypeScript definitions
[ERROR] There seems to be an unexpected error, try again with --debug for more information 

 ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                                                                                                                                                                                            │
│   Error: Failed to compile TypeScript definitions                                                                                                                                                                          │
│       at /Users/ben/dev/strapi/myplugin5/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]/node_modules/@strapi/pack-up/dist/index.js:835:19                           │
│       at Array.map (<anonymous>)                                                                                                                                                                                           │
│       at Observable._subscribe (/Users/ben/dev/strapi/myplugin5/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]/node_modules/@strapi/pack-up/dist/index.js:813:22)   │
│       at Observable._trySubscribe (/Users/ben/dev/strapi/myplugin5/node_modules/.pnpm/[email protected]/node_modules/rxjs/dist/cjs/internal/Observable.js:41:25)                                                                  │
│       at /Users/ben/dev/strapi/myplugin5/node_modules/.pnpm/[email protected]/node_modules/rxjs/dist/cjs/internal/Observable.js:35:31                                                                                             │
│       at Object.errorContext (/Users/ben/dev/strapi/myplugin5/node_modules/.pnpm/[email protected]/node_modules/rxjs/dist/cjs/internal/util/errorContext.js:22:9)                                                                 │
│       at Observable.subscribe (/Users/ben/dev/strapi/myplugin5/node_modules/.pnpm/[email protected]/node_modules/rxjs/dist/cjs/internal/Observable.js:26:24)                                                                      │
│       at /Users/ben/dev/strapi/myplugin5/node_modules/.pnpm/[email protected]/node_modules/rxjs/dist/cjs/internal/Observable.js:86:19                                                                                             │
│       at new Promise (<anonymous>)                                                                                                                                                                                         │
│       at Observable.toPromise (/Users/ben/dev/strapi/myplugin5/node_modules/.pnpm/[email protected]/node_modules/rxjs/dist/cjs/internal/Observable.js:84:16)                                                                      │
│                                                                                                                                                                                                                            │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

To Reproduce

create a new plugin with init

then run pnpm run build

Expected Behaviour

plugin should build

@innerdvations innerdvations added the issue: bug Issue reporting a bug label Aug 14, 2024
@alexandrebodin
Copy link
Member

Saw that too. it is easily fixable in the template but feels very ugly

import type { Core } from @strapi/strapi;

type Strapi = Core.strapi;


export default ....

Will work

@innerdvations innerdvations added the severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve label Nov 28, 2024
@gvillenave
Copy link

@alexandrebodin I'm not able to use the workaround, still getting the same failure even after adding the import and type definition in server/src/index.ts etc.

[ERROR] server/src/index.ts:23:1 - TS2742: The inferred type of 'default' cannot be named without a reference to '.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@strapi/types/dist/modules/documents'. This is likely not portable. A type annotation is necessary.

@gvillenave
Copy link

Strangely enough this works fine with Yarn.

@hebersolano
Copy link

As @alexandrebodin explains the solution, you have to import the Strapi type wherever it is needed.

import type { Core } from '@strapi/strapi';

type Strapi = Core.Strapi;

Error console example, import in server/src/index.ts, server/src/services/index.ts and server/src/controllers/index.ts

[ERROR]  server/src/index.ts:1:27 - TS1141: String literal expected.
[ERROR]  server/src/index.ts:1:34 - TS1109: Expression expected.
[ERROR]  server/src/index.ts:24:1 - TS2742: The inferred type of 'default' cannot be named without a reference to '.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@strapi/types/dist/core'. This is likely not portable. A type annotation is necessary.
[ERROR]  server/src/services/index.ts:3:1 - TS2742: The inferred type of 'default' cannot be named without a reference to '.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@strapi/types/dist/core'. This is likely not portable. A type annotation is necessary.
[ERROR]  server/src/controllers/index.ts:3:1 - TS2742: The inferred type of 'default' cannot be named without a reference to '.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@strapi/types/dist/core'. This is likely not portable. A type annotation is necessary.
[ERROR]  server/src/index.ts:1:34 - TS1109: Expression expected.
[ERROR]  server/src/index.ts:1:27 - TS1141: String literal expected.
[ERROR]  Failed to compile TypeScript definitions

@gvillenave
Copy link

@alexandrebodin any updates here? This is still reproducing with (as far as I can tell) anything other than yarn 1.22.22 + the workaround.

@innerdvations innerdvations added severity: medium If it breaks the basic use of the product but can be worked around and removed severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve labels Feb 10, 2025
@hanpaine
Copy link

Hi @gvillenave we have not had capacity to look at this yet I'm afraid. In future please do not directly tag team members 🙏 thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: bug Issue reporting a bug severity: medium If it breaks the basic use of the product but can be worked around
Projects
None yet
Development

No branches or pull requests

5 participants