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.

Support ES module scripts?

See original GitHub issue

I’ve tried writing a silly deploy script as an ES module, now that node has experimental support, but meow doesn’t grok this:

> yarn deploy
yarn run v1.21.0
$ node src/__scripts__/deploy.mjs
(node:5588) ExperimentalWarning: The ESM module loader is experimental.
myproj/node_modules/meow/index.js:15
const parentDir = path.dirname(module.parent.filename);
                                             ^

TypeError: Cannot read property 'filename' of undefined
    at Object.<anonymous> (myproj/node_modules/meow/index.js:15:46)

I’m curious of meow really needs to look up the parent module? If it’s part of meow’s magic, is there perhaps a work-around?

In my case, my script is a tiny part of a larger project, and at present I can’t / don’t want to invoke meow on the top-level thing. Instead I’m trying to write a tiny script that only happens to be the directory structure of myproj.

Is meow not a good fit here, or am I just missing something?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
jimthedevcommented, May 1, 2020

Turns out you can actually use this module in ES Modules as it exists, you just need to use some special syntax (createRequire) when importing it as shown in my PR.

0reactions
jimthedevcommented, Apr 27, 2020

Sadly looks like process.main is undefined until meow transitions over so ultimately we will need people to use pkg until then if they are using es modules.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript modules via script tag | Can I use... Support tables ...
Loading JavaScript module scripts (aka ES6 modules) using <script type="module"> Includes support for the nomodule attribute.
Read more >
JavaScript modules - MDN Web Docs
This guide gives you all you need to get started with JavaScript module syntax.
Read more >
ES modules in service workers - web.dev
Service workers can use static imports of ES modules to bring in extra code, as an alternative to importScripts().
Read more >
Using ES Modules in the Browser Today - SitePoint
This article will show you how you can use ES modules in the browser today. Until recently, JavaScript had no concept of modules....
Read more >
ES Modules | Dev Cheatsheets - Michael Currin
As of ES6 (ES2015), JavaScript supports a native module format called ES Modules, or ECMAScript Modules. This is modern way to do modules...
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