routes-gen: Invalid driver package name or file path.
Describe the bug
I installed the dependencies using npm add routes-gen @routes-gen/remix
and run routes-gen -d @routes-gen/remix
and I get the following error
Your Example Website or App
Private Repo
Steps to Reproduce the Bug or Issue
- Install dependencies with
npm
- Run the script with
npm
Expected behavior
Generate the routes
Screenshots or Videos
No response
Platform
- OS: macOS
- Browser: Chrome
- Version: 108.0
Additional context
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 15 (10 by maintainers)
Hi, sorry for the delay in getting back to you.
I think I’ve narrowed down the issue now thanks to the console log from your first comment.
I have set
"type":"module",
in my package.json file, which means all files with the .js extension are treated as ESM.I tried changing the file extension as the error message mentions (because the contents is definitely commonjs) but then I encounter this issue:
Since v1.6.8, remix.config supports both cjs and mjs file extensions, so I would recommend checking for each of these extensions before you throw an error because of a missing config file.
I believe by adding support for these file extensions, it should resolve our issue. (@danestves don’t forget to changes your file extensions to
.cjs
if they containmodule.exports
, or update the code inside the file to ESM code).If your source code is already ESM, you can import cjs and ESM the same way. It’s that easy.
If your source code is using cjs and you don’t want to convert it to esm, you won’t be able to use require, instead you have to use dynamic import. It’s probably not as complex as you think, this article explains it pretty well. https://adamcoster.com/blog/commonjs-and-esm-importexport-compatibility-examples
In short, you can try to require it in a try catch block, and if that fails, import it instead.