cornerstone3D
cornerstone3D copied to clipboard
fix: package exports
Context
The current main field in package.json would cause app fail to import @cornerstone/xxx packages.
For example the current main field in @cornerstonejs/core package.json is src/index.ts, this would import the package as source code. But after bundled, it should not be imported as source code in other's projects. It would case error: can not resolve src/index.ts in @cornerstonejs/core .
It could happen in framework like NextJS or any project that doesn't recognize @cornerstonejs/xxx package as source code.
As metioned in #882, but it is for beta 2 version
This PR is created for those using version 1
Changes & Results
Add exports field in package.json in these packages to distinguish cjs and mjs usage
- @cornerstonejs/core
- @cornerstonejs/tools
- @cornerstonejs/nifti-volume-loader
- @cornerstonejs/streaming-image-volume-loader
Testing
None
Checklist
PR
- [x] My Pull Request title is descriptive, accurate and follows the semantic-release format and guidelines.
Code
-
[x] My code has been well-documented (function documentation, inline comments, etc.)
-
[x] I have run the
yarn build:update-apito update the API documentation, and have committed the changes to this PR. (Read more here https://www.cornerstonejs.org/docs/contribute/update-api)
Public Documentation Updates
- [x] The documentation page has been updated as necessary for any public API additions or removals.
Tested Environment
- [x] "OS: Ubuntu 23.10
- [x] "Node version: 20.10.0 & 18.19.0
- [x] "Browser: Chrome 120.0.6099.201
Deploy Preview for cornerstone-3d-docs ready!
| Name | Link |
|---|---|
| Latest commit | a651873aacc3cb964c8eb78d67ef500a9791f126 |
| Latest deploy log | https://app.netlify.com/sites/cornerstone-3d-docs/deploys/65b224210c896200085d40ab |
| Deploy Preview | https://deploy-preview-960--cornerstone-3d-docs.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
For some reason this is failing the build You can try it
cd packages/dicomImageLoaderthenyarn buildit gives this error
Looks like the .webpack/webpack-bundle.js forgot to make @cornerstonejs/core package as external. I've added it in this PR.
But it should has nothing to do with the package.json changes. It should also be existing in the original repo.
Thanks for the update, one more thing. Can you please enhance the description of the PR on when it actually fails to import when you mentioned, which framework?
The current main field in package.json would cause app fail to import @cornerstone/xxx packages
Thanks for the update, one more thing. Can you please enhance the description of the PR on when it actually fails to import when you mentioned, which framework?
The current main field in package.json would cause app fail to import @cornerstone/xxx packages
My bad for not clearly describing it. Added in the description of this PR.
I know we merged in 2.x, since that was beta and less restrictions, but for 1.x which is considered stable I would like to get reproducible testing steps. What I'm looking for are steps (repo, any thing that I can clone, try) and shows the error and then try your fix and make sure it is fixed. You mentioned NextJS, do you have a playground in NextJS that you can share that would fail on the main branch but works when we apply this PR fix?
I know we merged in 2.x, since that was beta and less restrictions, but for 1.x which is considered stable I would like to get reproducible testing steps. What I'm looking for are steps (repo, any thing that I can clone, try) and shows the error and then try your fix and make sure it is fixed. You mentioned NextJS, do you have a playground in NextJS that you can share that would fail on the main branch but works when we apply this PR fix?
I can see your concern. Here's a reproduction link with stackbliz:
https://stackblitz.com/edit/stackblitz-starters-q3ogjh?file=app%2Fpage.tsx
Simply run this demo online will get this error:
Thanks for the test. I downloaded the project on stackBlitz to local, confirmed the bug, now I applied your patch/fix here, but still does not work.
Have you tried your fix in the stackBlitz you sent?
Thanks for the test. I downloaded the project on stackBlitz to local, confirmed the bug, now I applied your patch/fix here, but still does not work.
Have you tried your fix in the stackBlitz you sent?
If you want to fix this in the stackbliz. You can only apply the package.json changes to the local installed packages in node_modules
@Blackman99 These were my steps
- Downloaded your stackblitz to local
- yarn/npm install (don't remember which)
- Saw the original error you posted
- Went into the local node_modules in the project (downloaded)
- Applied the fixes
- Saw new error I posted above
Am i missing something?
@Blackman99 These were my steps
- Downloaded your stackblitz to local
- yarn/npm install (don't remember which)
- Saw the original error you posted
- Went into the local node_modules in the project (downloaded)
- Applied the fixes
- Saw new error I posted above
Am i missing something?
After the changes applied. You may also need to clear the next cache by deleting the .next directory. Then restart the project
I tried deleting the .next and doesn't work still show me the new error. Are you certain it works for you after you apply that patch?
I tried deleting the .next and doesn't work still show me the new error. Are you certain it works for you after you apply that patch?
Sorry, I forgot a change which is to remove main field in package.json
But removing main field would cause development become complex.
I understand that the current main field point to src is to provide convience for developing. So that the packages can reference each other during development.
But after bunduled. The main field should no longer be needed. And will cause the error. Using exports filed would be common practice.
Still no luck
I did remove .next first before yarn dev
That's strange. I'm using yarn by the way
I've noticed that in your screenshot. The package.json in the @cornerstonejs/streaming-image-volume-loader is not shown. Did you also apply the changes?
Yeah applied there, didn't notice not including it in the screenshot
I don't quite know the reason. My changes basically are the same.
And my /page compiling is passed as shown in the terminal.
I did a fresh download from stackblits and tried the steps, still the same new error. What is your node version? mine is 18.17.0
can you zip the whole folder with node_modules and everything and send it to me, just to see if that works, then we take a diff
I did a fresh download from stackblits and tried the steps, still the same new error. What is your node version? mine is 18.17.0
I've tried on node 20.10.0 and 18.19.0. And my OS is Ubuntu 23.10.
i think, it's very necessary for us to support MWA. for example react、angular、Vue .etc framework. resolve and pull it, it seems beneficial to development. thank you~
@baokeyu123 Have you tried the stack blitz locally and tried the fix here and can confirm it resolves it?
I've tried on Windows10. It works as expected. How can I give the node_modules.zip file? @sedghi
maybe dropbox or something? zip it
Try this: https://www.dropbox.com/scl/fi/49pnfgguek83m7210j801/node_modules.zip?rlkey=nkvy8o6dmp2lym0otqt60b2hq&dl=0
@IbrahimCSAE can you please check this for me? Please read through the conversation and reproducible steps and see if the fix works
I did it in beta version, can you check it @Blackman99 ?


