Stun3R / strapi-sdk-js

📦 Javascript SDK for your Strapi API
https://strapi-sdk-js.netlify.app
MIT License
143 stars 28 forks source link

Import has no construct signatures #190

Open selfagency opened 1 year ago

selfagency commented 1 year ago

Bug report

Describe the bug

Though I can clearly see the class constructor in both the mjs and d.ts files in the node_modules folder, I am unable to initialize the Strapi class due to a 'no construct signatures' error.

Steps to reproduce the behavior

See code sample below.

Expected behavior

For the Strapi SDK to initialize.

Screenshots

$ /Users/daniel/Developer/jewish-earth-alliance/node_modules/.bin/tsc
src/importer.ts:8:20 - error TS2351: This expression is not constructable.
  Type 'typeof import("/Users/daniel/Developer/jewish-earth-alliance/node_modules/strapi-sdk-js/dist/index")' has no construct signatures.

8 const strapi = new Strapi();
                     ~~~~~~

Found 1 error in src/importer.ts:8

Code snippets

All of these fail to load and yield the above error or similar.

import Strapi from 'strapi-sdk-js';
const strapi = new Strapi();
import Strapi from 'strapi-sdk-js';
const strapi = new Strapi.default();
import * as Strapi from 'strapi-sdk-js';
const strapi = new Strapi();
import * as Strapi from 'strapi-sdk-js';
const strapi = new Strapi.default();

System

Additional context

tsconfig.json

{
  "compilerOptions": {
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "baseUrl": "./",
    "declaration": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "inlineSourceMap": true,
    "isolatedModules": true,
    "module": "Node16",
    "moduleResolution": "NodeNext",
    "outDir": "./dist",
    "removeComments": true,
    "resolveJsonModule": true,
    "resolvePackageJsonExports": true,
    "resolvePackageJsonImports": true,
    "rootDir": "./src",
    "skipLibCheck": true,
    "strict": true,
    "target": "es2016",
    "types": [
      "node"
    ]
  },
  "exclude": [
    "node_modules",
    "**/*.spec.ts"
  ],
  "include": [
    "src/**/*"
  ]
}
henrik-clabs commented 1 month ago

Found this Stackoverflow Error TS2351

import Strapi, { StrapiOptions } from "strapi-sdk-js"
const TheStrapi = Strapi as unknown as typeof Strapi.default
const options: StrapiOptions = {
  url: "http://strapi-host/",
}
export const strapi = new TheStrapi(options)