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

[bug] - Print verbose alert of error when parsing config file instead of failing silently #572

Open
rihards-simanovics opened this issue Jun 9, 2024 · 4 comments

Comments

@rihards-simanovics
Copy link

Just had a weird encounter where Fantasticon refused to parse the .fantasticonrc.js even though it was formatted correctly.

The issue turned out to be with how the package.json was declaring the type of the package. It was set to "module", a default set by Vite create template, which meant that all common .js files needed to have a .cjs extension, I was only able to figure this out after manually adding the console.error(err).

Expected behaviour

Create a --verbose flag or print out a verbose error reporting on traceback and any other useful info i.e.:

user@hostpc:~/git/internal/project$ bun run generate-icons
$ fantasticon
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/user/git/internal/project/.fantasticonrc.js from /home/user/git/internal/project/node_modules/fantasticon/lib/cli/config-loader.js not supported.
.fantasticonrc.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename .fantasticonrc.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /home/user/git/internal/project/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

    at /home/user/git/internal/project/node_modules/fantasticon/lib/cli/config-loader.js:26:20
    at Generator.next (<anonymous>)
    at fulfilled (/home/user/git/internal/project/node_modules/fantasticon/lib/cli/config-loader.js:5:58) {
  code: 'ERR_REQUIRE_ESM'
}
SyntaxError: Unexpected token 'm', "module.exp"... is not valid JSON
    at JSON.parse (<anonymous>)
    at /home/user/git/internal/project/node_modules/fantasticon/lib/cli/config-loader.js:30:25
    at Generator.next (<anonymous>)
    at fulfilled (/home/user/git/internal/project/node_modules/fantasticon/lib/cli/config-loader.js:5:58)
Failed parsing configuration at '.fantasticonrc.js'

Actual Behaviour

All I get is Failed parsing configuration at '.fantasticonrc.js', which is needless to say is not helpful.

Also might be a good idea to add .cjs exension to a set of default imports or make this fetch dynamic by using regex.

issue blames:

@Dok11
Copy link

Dok11 commented Jun 11, 2024

I had same issue with Failed parsing configuration at '.fantasticonrc.js' but without any additional logs.
As I found the problem was next: there was a path codepoints: require('./icons.json'), in the config but this file did not exist at first run. To solve it I created the icons.json with empty object {}.

@rihards-simanovics
Copy link
Author

As I found the problem was next: there was a path codepoints: require('./icons.json'), in the config but this file did not exist at first run.

Weird NextJS doesn't have anything of that sorts in the config. Or at least not in the default template, perhaps it's something you've inherited from other project?

@Dok11
Copy link

Dok11 commented Jun 12, 2024

@rihards-simanovics
Copy link
Author

haven't really worked with codepoints before so not sure what it is. I'm guessing based on format it's a custom IDs for specific icon.

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

2 participants