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

Improve importMeta message -meow - The 'importMeta' option is required. Its value must be 'import.meta' at meow #222

Closed
dilraj-vidyard opened this issue Dec 18, 2022 · 7 comments

Comments

@dilraj-vidyard
Copy link

I apologize if this is clear for most people, but I've dealt with a lot of headaches with node --experimental-modules.

My Experience

When I imported meow, with:

import meow from 'meow';

And did const cli = meow();,

This is what I saw:

(node:23486) ExperimentalWarning: Importing JSON modules is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
file:///Users/dsingh/Documents/node-cli/dilraj/node_modules/meow/index.js:110
	if (!(options.importMeta && options.importMeta.url)) {
	              ^

TypeError: Cannot read properties of undefined (reading 'importMeta')
    at meow (file:///Users/dsingh/Documents/node-cli/dilraj/node_modules/meow/index.js:110:16)

I was convinced that it was something to do with the ES module stuff and it took me down the wrong path for hours.

The Solution

It wasn't until I went to the docs and searched specifically for the importMeta; (😮‍💨 definitely should have done that soon 🤦)

const cli = meow(); // ❌ TypeError: Cannot read properties of undefined (reading 'importMeta')

const cli = meow({ importMeta: import.meta }); // ✅ This fixed it

Proposal

  1. BOOST the error message on Google
    Thus, I decided to open an issue in case anyone else searches for the same issue.

  2. Maybe provider a clearer message?

I don't know enough about meow to offer a better message.

@dilraj-vidyard dilraj-vidyard changed the title Improve importMeta message -meow - The importMeta option is required. Its value must be import.meta`at meow Improve importMeta message -meow - The 'importMeta' option is required. Its value must be 'import.meta' at meow Dec 18, 2022
@so1ve
Copy link

so1ve commented Jan 26, 2023

:-(

@dilraj-vidyard
Copy link
Author

I know :(((( Forgive me

@LitoMore
Copy link
Contributor

I believe the error message is clear enough. You should read our documentation and examples before use.

@dilraj-vidyard
Copy link
Author

dilraj-vidyard commented Feb 12, 2023

nice

u must be fun at parties

@LitoMore
Copy link
Contributor

lol. Do you mean we didn't explain in the documentation why we mark this parameter as required?

Hmmm, maybe you are right.

Feel free to reopen it if you would like to discuss further.

@chuyaguo2014
Copy link

Coming here to thank you OP for posting this!

I had the same issue. 😅 It wasn't immediately clear to me in the example from the documentation that the importMeta was required (I thought it was part of the set up like the rainbow boolean option so it was only relevant for that particular 🦄 example).

I also misunderstood the error message. I thought

"TypeError: The `importMeta` option is required. Its value must be `import.meta`." 

meant I had to do something like:

{  importMeta: 'some-magic-meta-data-for-my-module-maybe-the-file-path-or-something' }

or maybe something more literal like:

{ importMeta: `import.meta` }

I believe I misread the documentation because the first example is a little long and the required options got buried by the rest of the example. Maybe something like this would be more obvious?

#!/usr/bin/env node
import meow from 'meow';
import foo from './lib/index.js';

const cli = meow(`text to display for the --help option`, 
  {
    importMeta: import.meta, // required 
    flags: {
	rainbow: {
		type: 'boolean',
		shortFlag: 'r'
	}
  }
});
/*
{
	input: ['unicorns'],
	flags: {rainbow: true},
	...
}
*/

foo(cli.input.at(0), cli.flags);

and then later on give a longer example where your users can describe the usage in more details? 🙂 🙏🏼

@tommy-mitchell
Copy link
Contributor

@chuyaguo2014 you should open a new issue suggesting more documentation. I like adding the // Required comment to the usage example.

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

No branches or pull requests

5 participants