Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK: Fix bundles #10053

Merged
merged 2 commits into from Dec 1, 2021
Merged

SDK: Fix bundles #10053

merged 2 commits into from Dec 1, 2021

Conversation

joselcvarela
Copy link
Member

@joselcvarela joselcvarela commented Nov 25, 2021

Fixes ##8079

Although this seemed to be fixed, for Nuxt builds it was complaining about
XMLHttpRequest is not defined

I believe the cause of this Rollup for SDK was only building for browsers, ignoring Node:

resolve({
browser: true,
}),

Inside Axios the getAdapater was always returning the xhrAdapter.

In order to fix this, I have inherited configuration from format-title with the slight difference that exports .mjs for ES modules instead of regular .js.
Now Is uses xhrAdapter for browsers and httpAdapter for Node.

Tested and working on Nuxt, React, Node CJS, Node MJS and TS-Node.

The problem was coming from rollup building only for browsers.
The solution is to specify build for browsers and Node.js.
This configuration is inherited from format-title package,
but with the slight difference that exports .mjs files
@rijkvanzanten
Copy link
Member

@joselcvarela The build doesn't seem to like that 🤔 Could you check what's up with

Error: src/cli/commands/instance/connect.ts(2,26): error TS7016: Could not find a declaration file for module '@directus/sdk'. '/home/runner/work/directus/directus/packages/sdk/dist/sdk.cjs.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/directus__sdk` if it exists or add a new declaration (.d.ts) file containing `declare module '@directus/sdk';`
Error: src/cli/commands/instance/disconnect.ts(2,26): error TS7016: Could not find a declaration file for module '@directus/sdk'. '/home/runner/work/directus/directus/packages/sdk/dist/sdk.cjs.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/directus__sdk` if it exists or add a new declaration (.d.ts) file containing `declare module '@directus/sdk';`
Error: src/core/extensions/instances.ts(1,26): error TS7016: Could not find a declaration file for module '@directus/sdk'. '/home/runner/work/directus/directus/packages/sdk/dist/sdk.cjs.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/directus__sdk` if it exists or add a new declaration (.d.ts) file containing `declare module '@directus/sdk';`
Error: src/core/sdk/storage.ts(1,26): error TS7016: Could not find a declaration file for module '@directus/sdk'. '/home/runner/work/directus/directus/packages/sdk/dist/sdk.cjs.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/directus__sdk` if it exists or add a new declaration (.d.ts) file containing `declare module '@directus/sdk';`
Error: src/toolbox.ts(1,57): error TS7016: Could not find a declaration file for module '@directus/sdk'. '/home/runner/work/directus/directus/packages/sdk/dist/sdk.cjs.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/directus__sdk` if it exists or add a new declaration (.d.ts) file containing `declare module '@directus/sdk';`
lerna ERR! npm run build exited 2 in '@directus/cli'
lerna WARN complete Waiting for 1 child process to exit. CTRL-C to exit immediately.
Error: Process completed with exit code 2.

@joselcvarela
Copy link
Member Author

Yeah, I am already on it 😁

@joselcvarela
Copy link
Member Author

@rijkvanzanten seems to be fixed now

@joselcvarela
Copy link
Member Author

Don't know why, but it seems you were not assigned as reviewer on this PR @rijkvanzanten. I am putting manually.

@rijkvanzanten
Copy link
Member

We can keep discussing optimizing the build on #10204

@rijkvanzanten rijkvanzanten added this to the v9-next milestone Dec 1, 2021
@rijkvanzanten rijkvanzanten merged commit de97879 into main Dec 1, 2021
@rijkvanzanten rijkvanzanten deleted the sdk/fix-bundles branch December 1, 2021 19:23
rijkvanzanten pushed a commit that referenced this pull request Dec 1, 2021
* Fix bundles
The problem was coming from rollup building only for browsers.
The solution is to specify build for browsers and Node.js.
This configuration is inherited from format-title package,
but with the slight difference that exports .mjs files

* fix types folder
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants