question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ECMAScript module loading error

See original GitHub issue

Thank you for your great package. I have one question:

When using the program with ESM (.mjs import) I get an error with the current version of Node (9.4.0).

(node:4290) ExperimentalWarning: The ESM module loader is experimental.
file:///Users/.../node_modules/apollo-upload-server/lib/types.mjs:1
import { GraphQLScalarType } from 'graphql'
         ^^^^^^^^^^^^^^^^^
SyntaxError: The requested module does not provide an export named 'GraphQLScalarType'
    at ModuleJob._instantiate (internal/loader/ModuleJob.js:86:19)
    at <anonymous>
error Command failed with exit code 1.

The problem should be resolved by changing the following lines in types.mjs:

import graphql from 'graphql'

const { GraphQLScalarType } = graphql

I think GraphQL exports currently only with CJS and not yet with ESM and therefore there is only the “default export”. Since you are running this program with Babel, you will not get an error. I use the package directly with Node.

https://nodejs.org/api/esm.html#esm_interop_with_existing_modules

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ghostcommented, Jan 30, 2018

Now, it works - thanks 👍

1reaction
ghostcommented, Jan 30, 2018

Ok, maybe you can use a temporary solution with a mix of default and variable import like this one: import myDefault, * as myModule from "my-module"; Not sure if it works for both, vanilla Node and Babel.

And then you can add a conditional assignment like that: const graphql = myDefault || myModule

Read more comments on GitHub >

github_iconTop Results From Across the Web

ES6 module loading: More complicated than you think
In order to autodetect modules in JavaScript programs, you would first have to parse the entire file. Modules need not use import ,...
Read more >
Error loading javascript .js files via ES6 module import from ...
Steps to reproduce the problem: 1. Create any html page that tries to use ECMAScript 2015 import to load javascript .js files from...
Read more >
Error while loading config - You appear to be using a native ...
I needed this configuration at the root of my directory babel.config.cjs. cjs is what is applicable for Nodejs when using "type"="module".
Read more >
JavaScript modules - MDN Web Docs
This guide gives you all you need to get started with JavaScript module syntax.
Read more >
How to Bypass ES Modules Errors in Next.js with Dynamic ...
In this article, I'll walk you through an error you may get when you are building JavaScript apps with Next.js, and how to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found