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

@strapi/plugin-sdk package.json validation too aggressive, cannot add additional exports #73

Closed
xenobytezero opened this issue Dec 28, 2024 · 4 comments · Fixed by #81
Closed
Labels
issue: bug Issue reporting a bug severity: medium If it breaks the basic use of the product but can be worked around source: sdk-plugin status: confirmed Confirmed by a Strapi Team member or multiple community members version: 5

Comments

@xenobytezero
Copy link

Bug report

Required System information

  • Node.js version: 22.12.0
  • NPM version: 10.9.0
  • Strapi version: 5.6.0
  • Database: MySQL
  • Operating system: Windows 11
  • Is your project Javascript or Typescript: Typescript

Describe the bug

When updating my plugins, I want to also export from the package a collection of types that can be used by developers/users of the plugin (things like the shape of the Config, shape of endpoint data, etc).

Now that Strapi v5 has switched to using the exports map I wanted to add my types to this export map.

    "exports": {
        "./package.json": "./package.json",
        "./strapi-admin": {
            "types": "./dist/admin/src/index.d.ts",
            "source": "./admin/src/index.ts",
            "import": "./dist/admin/index.mjs",
            "require": "./dist/admin/index.js",
            "default": "./dist/admin/index.js"
        },
        "./strapi-server": {
            "types": "./dist/server/src/index.d.ts",
            "source": "./server/src/index.ts",
            "import": "./dist/server/index.mjs",
            "require": "./dist/server/index.js",
            "default": "./dist/server/index.js"
        },
        "./types/*": "./dist-types/*.d.ts" // <--- Addition
    }

After adding it, trying to build/watch with the @strapi/plugin-sdk (strapi-plugin build) I get the following error

[ERROR] There seems to be an unexpected error, try again with --debug for more information 

 ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────┐│                                                                                                             
││   ValidationError: exports["./types/*"] must match the following: "/^\.\/.*\.json$/"                        
││   at createError (C:\Projects\GESDev\ges-v2\packages\editorjs\strapi-plugin-react-editorjs\node_modules\y   ││   up\lib\util\createValidation.js:54:21)                                                                    
││   at C:\Projects\GESDev\ges-v2\packages\editorjs\strapi-plugin-react-editorjs\node_modules\yup\lib\util\c   ││   reateValidation.js:72:107                                                                                 
││                                                                                                             
│└─────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

I also tried to use the object form of an export entry, and got a similar error, indicating that it had to use the same format as the strapi-admin/strapi-server objects, which doesn't work in this case.

@raulbalestra raulbalestra added issue: bug Issue reporting a bug severity: medium If it breaks the basic use of the product but can be worked around status: pending reproduction Waiting for free time to reproduce the issue, or more information flag: question Automation Flag to handle community questions labels Jan 15, 2025
Copy link
Contributor

This is a templated message

Hello @xenobytezero,

I see you are wanting to ask a question that is not really a bug report,

Please see the following contributing guidelines for asking a question here.

Thank you.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 15, 2025
@derrickmehaffy derrickmehaffy removed the flag: question Automation Flag to handle community questions label Jan 15, 2025
@derrickmehaffy derrickmehaffy transferred this issue from strapi/strapi Jan 15, 2025
@derrickmehaffy
Copy link
Member

Transferred to correct repo

@derrickmehaffy derrickmehaffy added source: sdk-plugin version: 5 status: confirmed Confirmed by a Strapi Team member or multiple community members and removed status: pending reproduction Waiting for free time to reproduce the issue, or more information labels Jan 15, 2025
@Boegie19
Copy link

Boegie19 commented Jan 15, 2025

Image

Also no documented way to add custom exports

@axe312ger
Copy link

Would love to see this fixed, it prevents me from exporting my stylesheets!

My plugin is very barebone, it includes just a little css. It bundles and works as expected.

But as soon I add this to my package.json:

"exports": {
      ...
    "./dist/style.css": "./dist/style.css"
  },

I get: │ ValidationError: exports["./dist/style.css"] must match the following: "/^\.\/.*\.json$/" │

Which is really unfortunate, because vite needs this to accept my css file as an import:

[plugin:vite:css] [postcss] Missing "./dist/style.css" specifier in "strapi-plugin-lexical" package

@import "strapi-plugin-lexical/dist/style.css";
import "strapi-plugin-lexical/dist/style.css";

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 source: sdk-plugin status: confirmed Confirmed by a Strapi Team member or multiple community members version: 5
Projects
Status: Fixed/Shipped
Status: Done
5 participants