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

Export clean ESM modules #1819

Closed
sebdeckers opened this issue Apr 13, 2019 · 12 comments
Closed

Export clean ESM modules #1819

sebdeckers opened this issue Apr 13, 2019 · 12 comments

Comments

@sebdeckers
Copy link

sebdeckers commented Apr 13, 2019

Using graphql@14.2.1

/node_modules/graphql/jsutils/instanceOf.mjs line 16

// See: https://expressjs.com/en/advanced/best-practice-performance.html#set-node_env-to-production
// See: https://webpack.js.org/guides/production/
export default process.env.NODE_ENV === 'production' ? // eslint-disable-next-line no-shadow
Uncaught ReferenceError: process is not defined
    at instanceOf.mjs:16

The check process.env.NODE_ENV === 'production' breaks in the browser when using ESM version of graphql package. Is it possible to remove before publishing to NPM? Without it the ESM files work perfectly.

I am not using Webpack/RollUp/Babel. Simply copying the ESM files from node_modules to my frontend folder using unbundle.

Related but different:

@IvanGoncharov IvanGoncharov added this to the v15.0.0 milestone Apr 13, 2019
@abdonrd
Copy link

abdonrd commented Apr 25, 2019

Also related but different: apollographql/graphql-tag#229

@Carglass
Copy link

Hello,

Id like to try to help with this issue. Using Unbundle, do you have a possibility to differentiate production from development code? I could not find a way to do it without using "bundlers". If there is not, the main issue, is that this export returns an optimized function for production, so that in the absence of the process.env, there is a choice to make about using the optimized function or the more helpful for development function. Any thoughts on this?

@dandv
Copy link

dandv commented May 19, 2019

Not sure if this will get any traction before Node 12 drops the --experimental-modules flag, because they've asked the community to not publish any ES modules until then.

@sebdeckers
Copy link
Author

While we are aware that the community has embraced the "module" field, it is unlikely that Node.js will adopt that field as many of the packages published using "module" include ES module JavaScript that may not evaluate in Node.js (because extensions are left off of filenames, or the code includes require statements, etc.). Please do not publish any ES module packages intended for use by Node.js until this is resolved.

  1. I am looking to run the ESM on the web, not Node.js. (Universal ESM would be nice tho.)
  2. The module field (et al.) is a de-facto practice. Supported by WebPack, RollUp, and Pika (afaik).

Compromise: Publish a distinct ESM package on NPM. Avoids conflict with Node.js and is backwards compatible with a variety of bundlers. E.g. lodash-es

Caveat, I'm not familiar with the reasons behind the above statement. Maybe this idea would cause problems in the long run. 🤷🏼‍♂️

@abdonrd
Copy link

abdonrd commented Jul 29, 2019

Any news here? Thanks in advance!

@Banou26
Copy link

Banou26 commented Jan 5, 2020

Could the ESM exports use complete import paths ?
e.g

- export { Source } from './source';
+ export { Source } from './source.mjs';

Since this results in errors like

Error: Cannot find module C:\dev\oz\packages\api\node_modules\graphql\language\source imported from C:\dev\oz\packages\api\node_modules\graphql\language\index.mjs

when using nodejs with ESM

@jaydenseric
Copy link

jaydenseric commented Jan 5, 2020

@Banou26 to achieve that, babel-plugin-transform-require-extensions can be used.

For example, here it is in action with extract-files:

@arlac77
Copy link

arlac77 commented Feb 10, 2020

@jaydenseric what is i want to use the raw npm content without further bundling either from node or the browser than the content must be 100% valid esm with full file names.

@jaydenseric
Copy link

@arlac77
Copy link

arlac77 commented Feb 10, 2020

@arlac77 it is:

https://unpkg.com/extract-files@7.0.0/lib/index.mjs

but deep inside there are still some imports without extension

Error: Cannot find module /Users/markus/build/hook-ci/node_modules/graphql/jsutils/devAssert imported from /Users/markus/build/hook-ci/node_modules/graphql/utilities/buildASTSchema.mjs

@arlac77
Copy link

arlac77 commented Feb 10, 2020

@IvanGoncharov
Copy link
Member

Released as 15.0.0-rc.2.
Last remaining issue tracked here: #2409

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

No branches or pull requests

8 participants