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

Failed script runs throw ENOENT for modules #1233

Open
gigaSproule opened this issue Jul 31, 2023 · 0 comments
Open

Failed script runs throw ENOENT for modules #1233

gigaSproule opened this issue Jul 31, 2023 · 0 comments

Comments

@gigaSproule
Copy link

Expected Behavior

When a script throws an error, the cause of the error should be printed out to console or simply provided as part of an error.

Actual Behavior

When a script throws an error, the renderStepsErrors tries to read the file of the migration script based on the stack using callsites. Unfortunately, when the types is set to module, the filename produced is a file:// string. So when it is passed into fs.readFileSync, node throws an ENOENT error, as fs can't handle file:// string values.

Possible Solution

Try to replace file:// from the filename returned by callsites before passing it to fs.readFileSync.

Steps to Reproduce

  1. Create a project with "type": "module" in the package.json
  2. Create a migration script that will fail (e.g. try to create a content type that already exists)
  3. Run the migration script

Context

We have a TypeScript project where some important libraries are ESM only, so we're migrating all of our code to produce ESM JavaScript. Our migration scripts are working perfectly fine and we can run them against Contentful, but when an error occurs (e.g. a script has run twice), we don't get a useful error message, just a stacktrace stating that one of the migration files can't be found, even though it exists. This means that we can't see what is the actual issue causing the script to fail.

Environment

  • Node Version: v18.16.1
  • Package Manager Version: yarn 3.6.0
  • Operating System: Darwin BMI05110.local 22.6.0 Darwin Kernel Version 22.6.0: Wed Jul 5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000 arm64
  • Package Version: v10.39.2
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

1 participant