Skip to content
New issue

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

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

Already on GitHub? # to your account

UMD with 'process.env.NODE_ENV' occurence (dev/prod) #681

Closed
UbikZ opened this issue Jan 18, 2019 · 5 comments
Closed

UMD with 'process.env.NODE_ENV' occurence (dev/prod) #681

UbikZ opened this issue Jan 18, 2019 · 5 comments

Comments

@UbikZ
Copy link
Contributor

UbikZ commented Jan 18, 2019

Hi there.

Describe the bug
Just want to use UMD build of react-i18next, but crashing because of process.env.NODE_ENV occurence inside development/production files.

Occurs in react-i18next version
https://unpkg.com/react-i18next@9.0.4/dist/umd/react-i18next.js
https://unpkg.com/react-i18next@9.0.4/dist/umd/react-i18next.min.js

To Reproduce
Steps to reproduce the behavior:

  1. Go https://codepen.io/anon/pen/ZVdRNX
  2. Check console

To Fix

  1. npm i rollup-plugin-replace -D
  2. In rollup.config.js :
  • Import rollup-plugin-replace
  • Add the plugin :
replace({
      'process.env.NODE_ENV': JSON.stringify(compress ? 'production' : 'development'),
}),

Thank's.

Gabriel.

@jamuhl
Copy link
Member

jamuhl commented Jan 18, 2019

that comes from react-is which is used by hoist-non-react-statics -> https://unpkg.com/react-is@16.7.0/index.js

we guard our calls like: https://github.com/i18next/react-i18next/blob/master/src/utils.js#L16

the only thing you can do is adding:

<script>process = { env: { NODE_ENV: 'production' } }</script>

@UbikZ
Copy link
Contributor Author

UbikZ commented Jan 18, 2019

Sorry, but I don't get it.

The process.env.NODE_ENV is always computed in UMD builds in order to remove some code from the build if production mode is enabled or not.

If react-is does not need the block code inside the if (process.env.NODE_ENV !== "production") { in production, your react-i18next production build will not needed it neither.
Same, if react-is must have the bloc in development mode, your react-i18next dev build should always have it.

Am I missing something ?

@jamuhl
Copy link
Member

jamuhl commented Jan 18, 2019

Not working like that...building a module you pull in dependencies...those are commonjs independent of rollup outputting umd in the end -> therefore it ends up like it is.

If you like to create a build (hardcoded production and development) like react-is does it - feel free to provide that as a PR...would be highly appreciated

@UbikZ
Copy link
Contributor Author

UbikZ commented Jan 21, 2019

The pull-request #683 works like a charm for UMD build.
Can you check all is good for you ?
Thank's.

EDIT: I have just commit the package.json and rollup.config.js files, not the build one.

@jamuhl
Copy link
Member

jamuhl commented Jan 22, 2019

published in react-i18next@9.0.5

@jamuhl jamuhl closed this as completed Jan 22, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants