contentful / contentful-management.js

JavaScript library for Contentful's Management API (node & browser)
https://contentful.github.io/contentful-management.js
MIT License
272 stars 97 forks source link

Svelte kit Adapter Issue #1799

Open tiddle opened 1 year ago

tiddle commented 1 year ago

This is the error i'm getting:

> Using @sveltejs/adapter-node
Circular dependency: node_modules/contentful-management/dist/es-modules/entities/index.js -> node_modules/contentful-management/dist/es-modules/entities/app-definition.js -> node_modules/contentful-management/dist/es-modules/create-app-definition-api.js -> node_modules/contentful-management
/dist/es-modules/entities/index.js
Circular dependency: node_modules/contentful-management/dist/es-modules/entities/app-definition.js -> node_modules/contentful-management/dist/es-modules/create-app-definition-api.js -> node_modules/contentful-management/dist/es-modules/entities/app-definition.js
Circular dependency: node_modules/contentful-management/dist/es-modules/entities/index.js -> node_modules/contentful-management/dist/es-modules/entities/entry.js -> node_modules/contentful-management/dist/es-modules/create-entry-api.js -> node_modules/contentful-management/dist/es-modules/e
ntities/index.js
Circular dependency: node_modules/contentful-management/dist/es-modules/entities/index.js -> node_modules/contentful-management/dist/es-modules/entities/environment.js -> node_modules/contentful-management/dist/es-modules/create-environment-api.js -> node_modules/contentful-management/dist/
es-modules/entities/index.js
Circular dependency: node_modules/contentful-management/dist/es-modules/entities/index.js -> node_modules/contentful-management/dist/es-modules/entities/environment.js -> node_modules/contentful-management/dist/es-modules/create-environment-api.js -> node_modules/contentful-management/dist/
es-modules/entities/ui-config.js -> node_modules/contentful-management/dist/es-modules/create-ui-config-api.js -> node_modules/contentful-management/dist/es-modules/entities/index.js
Circular dependency: node_modules/contentful-management/dist/es-modules/entities/index.js -> node_modules/contentful-management/dist/es-modules/entities/environment.js -> node_modules/contentful-management/dist/es-modules/create-environment-api.js -> node_modules/contentful-management/dist/
es-modules/entities/user-ui-config.js -> node_modules/contentful-management/dist/es-modules/create-user-ui-config-api.js -> node_modules/contentful-management/dist/es-modules/entities/index.js
Circular dependency: node_modules/contentful-management/dist/es-modules/entities/index.js -> node_modules/contentful-management/dist/es-modules/entities/environment-template.js -> node_modules/contentful-management/dist/es-modules/create-environment-template-api.js -> node_modules/contentfu
l-management/dist/es-modules/entities/index.js
Circular dependency: node_modules/contentful-management/dist/es-modules/entities/index.js -> node_modules/contentful-management/dist/es-modules/entities/organization.js -> node_modules/contentful-management/dist/es-modules/create-organization-api.js -> node_modules/contentful-management/dis
t/es-modules/entities/index.js
Circular dependency: node_modules/contentful-management/dist/es-modules/entities/index.js -> node_modules/contentful-management/dist/es-modules/entities/space.js -> node_modules/contentful-management/dist/es-modules/create-space-api.js -> node_modules/contentful-management/dist/es-modules/e
ntities/index.js
error during build:
RollupError: "default" is not exported by "node_modules/contentful-management/dist/es-modules/contentful-management.js", imported by ".svelte-kit/adapter-node/entries/pages/sverdle/_page.server.ts.js".
    at error (file:///home/carlo/workspace/test-app/node_modules/rollup/dist/es/shared/node-entry.js:2125:30)
    at Module.error (file:///home/carlo/workspace/test-app/node_modules/rollup/dist/es/shared/node-entry.js:13438:16)
    at Module.traceVariable (file:///home/carlo/workspace/test-app/node_modules/rollup/dist/es/shared/node-entry.js:13845:29)
    at ModuleScope.findVariable (file:///home/carlo/workspace/test-app/node_modules/rollup/dist/es/shared/node-entry.js:12404:39)
    at ReturnValueScope.findVariable (file:///home/carlo/workspace/test-app/node_modules/rollup/dist/es/shared/node-entry.js:6965:38)
    at ChildScope.findVariable (file:///home/carlo/workspace/test-app/node_modules/rollup/dist/es/shared/node-entry.js:6965:38)
    at MemberExpression.bind (file:///home/carlo/workspace/test-app/node_modules/rollup/dist/es/shared/node-entry.js:9317:49)
    at CallExpression.bind (file:///home/carlo/workspace/test-app/node_modules/rollup/dist/es/shared/node-entry.js:5738:23)
    at CallExpression.bind (file:///home/carlo/workspace/test-app/node_modules/rollup/dist/es/shared/node-entry.js:9668:15)
    at ExpressionStatement.bind (file:///home/carlo/workspace/test-app/node_modules/rollup/dist/es/shared/node-entry.js:5738:23)

This is from a fresh install of a TS version of a svelte kit with it's demo app.

Steps to reproduce:

  1. Install sveltekit with npm create svelte@latest my-app
  2. I don't think any of the options matter when creating the app, I just installed the demo app to make things easier
  3. install contentful-management and adapter via npm i -D contentful-management @sveltejs/adapter-node
  4. In svelte.config.js change '@sveltejs/adapter-auto'; to '@sveltejs/adapter-node';
  5. In a +page.server.[ts/js], doesn't matter which, add import contentful from 'contentful-management';
  6. In the same +page.server.[ts/js] the following code in a function or something, doesn't really matter where
    const aa = contentful.createClient({
    accessToken: 'foo'
    });
  7. Execute npm run build

It will seem like it's working until the > Using @sveltejs/adapter-node then the error occurs.

Note: I've also tried it with @sveltejs/adapter-deno and the same issue occurs.

How do i fix this?

tiddle commented 1 year ago

Okie, so as a work around you can do the following:

import * as contentful from 'contentful-management';

then in your function you can do:

return contentful.default.createClient(
        {
            accessToken: 'foo'
        },

It still has the Circular Dependency warnings, but it does compile.