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

process.env dependency causes issue in browser environment #141

Open
isawk opened this issue Jan 12, 2025 · 1 comment · May be fixed by #145
Open

process.env dependency causes issue in browser environment #141

isawk opened this issue Jan 12, 2025 · 1 comment · May be fixed by #145

Comments

@isawk
Copy link

isawk commented Jan 12, 2025

I encountered the following error when setting up the jdm-editor library in a browser environment:

✘ [ERROR] TS2591: Cannot find name 'process'. Do you need to install type definitions for node? Try npm i --save-dev @types/node and then add 'node' to the types field in your tsconfig. [plugin angular-compiler] node_modules/immer/src/utils/errors.ts:40:5: 40 │ if (process.env.NODE_ENV !== "production") {

This issue seems to arise because the immer dependency is using process.env.NODE_ENV, which is a Node.js environment variable not available in browser environments.

Upon investigating further, I noticed that the issue can be resolved by adjusting the imports in the index.d.ts file. Specifically, the WritableDraft type is imported directly from immer/src/types/types-external, which leads to this issue. Replacing the import like this:

import { WritableDraft } from 'immer';

resolved the problem in my setup.

Proposed Solution:

- import { WritableDraft } from 'immer/src/types/types-external';
+ import { WritableDraft } from 'immer';

Perhaps update below for next build/release
image

isawk added a commit to isawk/jdm-editor that referenced this issue Feb 15, 2025
isawk added a commit to isawk/jdm-editor that referenced this issue Feb 15, 2025
@isawk
Copy link
Author

isawk commented Feb 15, 2025

Temporary fix

install patch-package

npm install patch-package --save-dev

Edit index.d.ts with the right import

edit node_modules/@gorules/jdm-editor/dist/index.d.ts

-import { WritableDraft } from 'immer/src/types/types-external';`
+import { WritableDraft } from 'immer';

Create patch file
npx patch-package @gorules/jdm-editor

update package.json

"scripts": {
...
  "postinstall": "patch-package"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant