Open y-lobau opened 5 months ago
I can confirm I have the same issue in version 11.25.3
of the contentful-management
package and that @y-lobau 's workaround works for me too.
It would be good to have this addressed though as the ES6 import example in the documentation does not work!
@y-lobau Interesting, are you using some compiler/transpiler that modifies the import somehow? I wound up on this issue because I actually got the opposite behavior:
package.json
{
"name": "example",
"version": "1.0.0",
"private": "true",
"main": "index.js",
"type": "module",
"dependencies": {
"contentful-management": "11.24.3"
}
}
index.js
import contentful from "contentful-management";
console.log(contentful.createClient);
Running node .
yields:
[Function: createClient]
If I change index.js
as follows:
import { createClient } from "contentful-management";
console.log(createClient);
I get:
file:///(...)/index.js:1
import { createClient } from "contentful-management";
^^^^^^^^^^^^
SyntaxError: Named export 'createClient' not found. The requested module 'contentful-management' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'contentful-management';
const { createClient } = pkg;
at ModuleJob._instantiate (node:internal/modules/esm/module_job:134:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:217:5)
at async ModuleLoader.import (node:internal/modules/esm/loader:323:24)
at async loadESM (node:internal/process/esm_loader:28:7)
at async handleMainPromise (node:internal/modules/run_main:120:12)
Node.js v21.7.1
My .tsconfig looks as follows: Maybe it has something to do with the situation.
The documentation states:
When running this code from within the Contentful App (react), the contentful variable is undefined.
I was able to make it work with the following instead:
Node.js: v21.7.1 contentful-management: 11.24.3