Open romeguarin opened 10 months ago
Bump and relates to https://github.com/contentful/contentful.js/issues/2157
I verified the linked issue was resolved as of Contentful.js 10.9.0+ so I assume this one is too - though I cannot verify this angular specific issue myself, but I would assume this ticket could be closed now
I am having the same problem with astro.
astro: 4.12.2 node: 20.16.0 pnpm: 9.6.0 contentful: 10.13.1
import { createClient } from "contentful";
export const getStaticPaths = (async ({ paginate }) => {
const client = createClient({
space: "***",
accessToken: "****",
environment: "***",
});
return paginate([], { pageSize: 2 });
})
20:27:15 [ERROR] [vite] Named export 'createClient' not found. The requested module 'contentful' 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';
const {createClient} = pkg;
Stack trace:
at /*****/node_modules/.pnpm/vite@5.3.5_@types+node@18.19.43/node_modules/vite/dist/node/chunks/dep-mCdpKltl.js:51736:15
Issues like this should be resolved with our latest SDK version (v11).
Can you please test if this new version works for your setup? @msickpaler @nathanlaingzigzag @romeguarin
Expected Behavior
Contentful package should be available as ES modules. Any objects imported from contentful should not throw a warning when building in Angular CLI.
Actual Behavior
When
createClient
is used, the Angular CLI throws a warning during build / start commands.warning from angular cli build (this is when installing contentful on a local angular library, imported by the app being built and started):
Possible Workaround
Add
contentful
on angular.json'sallowedCommonJsDependencies
Steps to Reproduce
createClient
fromcontentful
, regardless of its configuration, inside a component's constructor.Context
ESM modules is now the recommended approach instead of CommonJs
Environment