Support ES module scripts?
See original GitHub issueI’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:
- Created 4 years ago
- Reactions:2
- Comments:6 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
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.