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

'main' cjs import has the wrong file name if NODE_ENV is production #1037

Closed
3 tasks done
mrdaniellewis opened this issue Apr 17, 2023 · 6 comments
Closed
3 tasks done
Labels

Comments

@mrdaniellewis
Copy link

🐛 Bug Report

If you import immer using require and NODE_ENV is set to "production", then the import fails.

The build is referencing the wrong file name.

// This is the contents of dist/cjs/index.js in your npm package

'use strict'

if (process.env.NODE_ENV === 'production') {
  module.exports = require('./immer.cjs.production.min.js')
} else {
  module.exports = require('./immer.cjs.development.js')
}

The file ./immer.cjs.production.min.js does not exist. It is called ./immer.cjs.production.js. That is, without the min.

To Reproduce

const { produce } = require('immer');

Make sure NODE_ENV === 'production'

Observed behaviour

Error Cannot find module './immer.cjs.production.min.js'

Expected behaviour

I expected to import immer.

Environment

We only accept bug reports against the latest Immer version.

  • Immer version:
  • I filed this report against the latest version of Immer
  • Occurs with setUseProxies(true)
  • Occurs with setUseProxies(false) (ES5 only)
@markerikson
Copy link
Contributor

Whoops, that's half my fault. I think I had tweaked the filenames and wrote the index.js generation string, then mweststrate changed them back and didn't realize the index.js string needed to get tweaked too.

@github-actions
Copy link
Contributor

🎉 This issue has been resolved in version 10.0.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@dliebner
Copy link

How do you include immer via CDN now?

@markerikson
Copy link
Contributor

There's now an ESM module that you can use: https://unpkg.com/browse/immer@10.0.1/dist/immer.production.mjs

What's your use case for loading Immer (or anything else) from a CDN?

@dliebner
Copy link

What's your use case for loading Immer (or anything else) from a CDN?

Ease of use, it's how I'm used to using external libraries, cross-site caching?

Should I just bundle it from now on?

@markerikson
Copy link
Contributor

As far as I know, cross-site caching died a few years ago when browsers changed cache implementations due to security concerns.

Generally, the "modern" way to do non-bundled JS apps is to load everything as ES modules. But yes, bundling certainly simplifies the deployment and loading steps.

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

Successfully merging a pull request may close this issue.

3 participants