Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

require in .mjs files #1589

Closed
jaydenseric opened this issue Jan 29, 2018 · 7 comments
Closed

require in .mjs files #1589

jaydenseric opened this issue Jan 29, 2018 · 7 comments

Comments

@jaydenseric
Copy link
Contributor

jaydenseric commented Jan 29, 2018

It is invalid for require to appear in .mjs files. This is currently happening in distributed files:

screen shot 2018-01-29 at 3 39 59 pm

screen shot 2018-01-29 at 3 35 59 pm

Version

  • react-apollo@^2.1.0-beta.0
@rosskevin
Copy link
Contributor

Regarding require, there are a few in the codebase for legacy imports, where that is the only way to typescript-appropriately import, other than that the rest are import syntax.

import x = require() syntax won't work based on our tsconfig module, but import * as x or import x also won't work because these are commonjs modules that use module.exports = x.

If you can figure out how to import these and have tsc be happy - I'm happy to know that solution.

@rosskevin
Copy link
Contributor

It looks like #1617 will solve the requires.

@jaydenseric
Copy link
Contributor Author

jaydenseric commented Feb 3, 2018

Kind of related: babel/babel#7294. There is a workaround I have shipped in apollo-upload-server, to get native ESM and fallback CJS build targets to work from a common ES6 source that imports a third party CJS module.

@leoasis
Copy link
Contributor

leoasis commented Feb 5, 2018

Does .mjs allow importing common js .js files? If the answer is yes, then maybe we could wrap the packages and provide a default (or named) export, something like this:

// some_file.mjs
import invariant from './invariant';
...
// invariant.js
exports.default = require('invariant');

@hwillson
Copy link
Member

.mjs support was removed. Thanks!

@AgronKabashi
Copy link

This is unfortunately still an issue when bundling with Rollup.
I don't see why the change was reverted as apollo-client was suffering from the same issue but they got it working here: https://github.com/apollographql/apollo-client/pull/4158/files.

@rosskevin
Copy link
Contributor

We have a new esm build already merged and will be released next.

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

No branches or pull requests

5 participants