eigengrau-ch / strapi-plugin-cookie-manager

MIT License
19 stars 7 forks source link

Argument of type '"api::cookie.cookie"' is not assignable to parameter of type 'ContentType'. #27

Open netzpixel opened 3 months ago

netzpixel commented 3 months ago

After a fresh install I get 3 errors right away. I tried changing the two files:

No clue what to change that it works. I'm on the latest version of strapi.

2024-05-26 22:04:20 WARNING in ../node_modules/strapi-plugin-cookie-manager/admin/src/pages/App/index.js 10:44-52 2024-05-26 22:04:20 export 'NotFound' (imported as 'NotFound') was not found in '@strapi/helper-plugin' (possible exports: AnErrorOccurred, AppInfoContext, AppInfoProvider, AppInfosContext, AppInfosProvider, AutoReloadOverlayBlockerContext, AutoReloadOverlayBlockerProvider, Body, CheckPagePermissions, CheckPermissions, ConfirmDialog, ContentBox, ContentManagerEditViewDataManagerContext, CustomFieldsContext, CustomFieldsProvider, DateTimePicker, DynamicTable, EmptyBodyTable, EmptyStateLayout, FilterListURLQuery, FilterPopoverURLQuery, Form, GenericInput, GuidedTourContext, GuidedTourProvider, InjectionZone, LibraryContext, LibraryProvider, Link, LinkButton, LoadingIndicatorPage, NoContent, NoMedia, NoPermissions, NotAllowedInput, NotificationsContext, NotificationsProvider, OverlayBlockerContext, OverlayBlockerProvider, PageSizeURLQuery, PaginationURLQuery, RBACContext, RBACProviderContext, ReactSelect, RelativeTime, RemoveRoundedButton, Root, SearchURLQuery, SettingsPageTitle, SortIcon, Status, StopPropagation, StrapiAppContext, StrapiAppProvider, Table, TrackingContext, TrackingProvider, auth, contentManagementUtilRemoveFieldsFromData, difference, findMatchingPermissions, formatContentTypeData, formatPermissionsForRequest, getAPIInnerErrors, getFetchClient, getFileExtension, getOtherInfos, getType, getYupInnerErrors, hasPermissions, normalizeAPIError, onRowClick, prefixFileUrlWithBackendUrl, prefixPluginTranslations, pxToRem, request, setHexOpacity, shouldCheckPermissions, stopPropagation, to, translatedErrors, useAPIErrorHandler, useAppInfo, useAppInfos, useAutoReloadOverlayBlocker, useCMEditViewDataManager, useCallbackRef, useClipboard, useCollator, useCustomFields, useFetchClient, useFilter, useFocusInputField, useFocusWhenNavigate, useGuidedTour, useLibrary, useLockScroll, useNotification, useOverlayBlocker, usePersistentState, useQuery, useQueryParams, useRBAC, useRBACProvider, useSelectionState, useStrapiApp, useTableContext, useTracking, wrapAxiosInstance) 2024-05-26 22:04:20 @ ../node_modules/strapi-plugin-cookie-manager/admin/src/index.js 2024-05-26 22:04:20 @ ../node_modules/strapi-plugin-cookie-manager/strapi-admin.js 2024-05-26 22:04:20 @ ./.strapi/client/app.js 5:0-70 17:22-35 2024-05-26 22:04:20 2024-05-26 22:04:20 ERROR in ./src/api/cookie/controllers/cookie.ts:7:47 2024-05-26 22:04:20 TS2345: Argument of type '"api::cookie.cookie"' is not assignable to parameter of type 'ContentType'. 2024-05-26 22:04:20 5 | import { factories } from '@strapi/strapi' 2024-05-26 22:04:20 6 | 2024-05-26 22:04:20 > 7 | export default factories.createCoreController('api::cookie.cookie'); 2024-05-26 22:04:20 | ^^^^^^^^^^^^^^^^^^^^ 2024-05-26 22:04:20 8 | 2024-05-26 22:04:20 2024-05-26 22:04:20 ERROR in ./src/api/cookie/routes/cookie.ts:7:43 2024-05-26 22:04:20 TS2345: Argument of type '"api::cookie.cookie"' is not assignable to parameter of type 'ContentType'. 2024-05-26 22:04:20 5 | import { factories } from '@strapi/strapi'; 2024-05-26 22:04:20 6 | 2024-05-26 22:04:20 > 7 | export default factories.createCoreRouter('api::cookie.cookie'); 2024-05-26 22:04:20 | ^^^^^^^^^^^^^^^^^^^^ 2024-05-26 22:04:20 8 | 2024-05-26 22:04:20 2024-05-26 22:04:20 ERROR in ./src/api/cookie/services/cookie.ts:1:18 2024-05-26 22:04:20 TS2304: Cannot find name 'createCoreService'. 2024-05-26 22:04:20 > 1 | module.exports = createCoreService('api::cookie.cookie', ({ strapi }) => ({ 2024-05-26 22:04:20 | ^^^^^^^^^^^^^^^^^ 2024-05-26 22:04:20 2 | async find(params) { 2024-05-26 22:04:20 3 | const { pagination } = await super.find(params); 2024-05-26 22:04:20 4 | const results = await strapi.entityService.findMany("api::cookie.cookie", Object.assign(params, {

saad12035 commented 3 months ago

I am also facing the same exact error on my strapi build

eigengrau-ch commented 3 months ago

Thanks for reporting the issue you are having with. Can you provide me the exact strapi version you are having the issue with? I will take a look at it within the next couple of day.

eigengrau-ch commented 3 months ago

@netzpixel I just found some time to investigate into the issue you are having. When using the latest strapi 4.24.3, I have encountered an issue with the automatic generation of the content types. Please report me if the following fixes your issue:

  1. Upgrade the plugin to version 1.2.4
  2. Delete the following content types folders which were generated by the plugin: ./src/api/cookie/ ./src/api/cookie-category/ ./src/api/cookie-popup/
  3. Run strapi with yarn develop or npm develop
  4. Make the changes according to the documentation inside of: ./src/api/cookie/services/cookie.js ./src/api/cookie-category/services/cookie-category.js
  5. Now it should work
saad12035 commented 3 months ago

@netzpixel I just found some time to investigate into the issue you are having. When using the latest strapi 4.24.3, I have encountered an issue with the automatic generation of the content types. Please report me if the following fixes your issue:

1. Upgrade the plugin to version `1.2.4`

2. Delete the following content types folders which were generated by the plugin:
   `./src/api/cookie/`
   `./src/api/cookie-category/`
   `./src/api/cookie-popup/`

3. Run strapi with `yarn develop` or `npm develop`

4. Make the changes according to the documentation inside of:
   `./src/api/cookie/services/cookie.js`
   `./src/api/cookie-category/services/cookie-category.js`

5. Now it should work

This didn't worked for me

Screenshot 2024-05-29 at 5 33 45 PM
eigengrau-ch commented 3 months ago

@netzpixel Alright, I managed to reproduce the issue when using strapi with typescript. It seems to be a bug with a strapi function which is called by the plugin when generating the content types. Unfortunately, I can't fix it in the plugin right now. But I can help you fixing it manually. Here's how you do it:

  1. Make sure that the attributes draftAndPublish has the value false inside of ./src/api/cookie-popup/content-types/cookie-popup/schema.json
  2. Copy and paste the routes & services folder from for example ./src/api/cookie-category into ./src/api/cookie-popup/. Then rename these files and the names inside the code accordingly from cookie-category to cookie-popup.
  3. After saving the files, run yarn strapi ts:generate-types
  4. Then last but not least, run yarn develop
  5. Now the errors should be gone and the content types should have the correct fields in it
saad12035 commented 3 months ago

Worked for me thanks