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

fix: wrong cjs/esm builds #1305

Closed
wants to merge 1 commit into from

Conversation

perzeuss
Copy link
Contributor

@perzeuss perzeuss commented Oct 27, 2023

Description of changes

Summarize the changes made by this PR.

Test plan

How are these changes tested?

  • run npx verdaccio
  • create the file clients/js/.npmrc with content registry=http://localhost:4873
  • increase the package version
  • run npm publish
  • start a clean js project
    • place the same .npmrc here
    • install chromadb yarn add chromadb or npm install chromadb
    • create a index.js with content const { ChromaClient } = require('chromadb'); new ChromaClient().heartbeat();
    • run node index.js
    • you should see an error that chroma wasn't able to connect - this means the chromadb client is working ✅ cjs is working
      • if your local chroma instance is running, you won't see any errors
    • add "type":"module" to the package.json
    • change the content of index.js to import { ChromaClient } from 'chromadb'; new ChromaClient().heartbeat();
    • you should see an error that chroma wasn't able to connect - this means the chromadb client is working ✅ esm is working
      • if your local chroma instance is running, you won't see any errors

Documentation Changes

Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the docs repository?

@github-actions
Copy link

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readbility, Modularity, Intuitiveness)

@jeffchuber jeffchuber self-requested a review October 27, 2023 20:32
@jeffchuber
Copy link
Contributor

jeffchuber commented Oct 27, 2023

@perzeuss thanks for this!!

I got to this part:

change the content of index.js to import { ChromaClient } from 'chromadb'; new ChromaClient().heartbeat();

and then I couldn't get further.

yarn run v1.22.19
warning package.json: No license field
$ node index.js
file:///Users/jeff/src2/cleanjsproj/index.js:2
import { ChromaClient } from 'chromadb';
         ^^^^^^^^^^^^
SyntaxError: Named export 'ChromaClient' not found. The requested module 'chromadb' 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 'chromadb';
const { ChromaClient } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:131:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:213:5)
    at async ModuleLoader.import (node:internal/modules/esm/loader:308:24)
    at async loadESM (node:internal/process/esm_loader:42:7)
    at async handleMainPromise (node:internal/modules/run_main:66:12)

Node.js v20.6.1
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

index.js

// const { ChromaClient } = require('chromadb'); 
import { ChromaClient } from 'chromadb';
new ChromaClient().heartbeat().then((res) => console.log('Connected!', res));

package.json

{
  "dependencies": {
    "chromadb": "^1.5.14"
  },
  "scripts": {
    "start": "node index.js"
  },
  "type": "module"
}

I have verified verdaccio is working correctly and respecting .npmrc, registry=http://localhost:4873

jeffchuber added a commit that referenced this pull request Nov 7, 2023
should be stacked on top of
#1305

merge #1305 first 

to ship this, we are removing `WebAI` and `Transformers` support (they
are much trickier). They will be added back soon.

---------

Co-authored-by: Pascal Malbranche <11357019+perzeuss@users.noreply.github.com>
@jeffchuber
Copy link
Contributor

closing as these improvements were landed in the other branch - thank you so much for this!

@jeffchuber jeffchuber closed this Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants