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

Migrator.fromFileSystem fails on Windows under moduleResolution:bundler option in tsconfig.json #4297

Open
sukazavr opened this issue Jan 20, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@sukazavr
Copy link

What version of Effect is running?

No response

What steps can reproduce the bug?

Run packages/sql-mssql/examples/ on Windows 10

Use bundler in tsconfig.json

  "compilerOptions": {
    // ts version and module resolution (use the lasted ts/js features and types)
    "lib": ["ESNext", "dom", "dom.iterable"],
    "target": "ESNext",
    "module": "ESNext",
    "moduleDetection": "force",
    "moduleResolution": "bundler",

What is the expected behavior?

Migrations should be loaded and run successfully

What do you see instead?

ERROR (#0):
  MigrationError: Could not import migration "1_mvp"

  Error: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:'
      at _ (D:\Projects\CA Price\node_modules\@effect\sql\src\Migrator.ts:151:11)
      at cause (D:\Projects\CA Price\node_modules\effect\src\internal\core-effect.ts:165:18)
      at sql.transaction

Additional information

Fix is needed in packages/sql/src/Migrator/FileSystem.ts

Change the line: https://github.com/Effect-TS/effect/blob/bec5ea459a363b7893f106643b4fb61a5246f722/packages/sql/src/Migrator/FileSystem.ts#L34C25-L34C51

Instead of ${directory}/${basename} it should be file://${directory}/${basename} for Windows OS.

This primitive solution was tested on my machine. We have to make import call OS agnostic, perhaps by adding some conditions?

@sukazavr sukazavr added the bug Something isn't working label Jan 20, 2025
@sukazavr
Copy link
Author

nodejs/node#31710 (comment)

As per node.js documentation:

The specifier of an import statement is the string after the from keyword, e.g. 'path' in import { sep } from 'path'. Specifiers are also used in export from statements, and as the argument to an import() expression.

There are four types of specifiers:

  • Bare specifiers like 'some-package'. They refer to an entry point of a package by the package name.
  • Deep import specifiers like 'some-package/lib/shuffle.mjs'. They refer to a path within a package prefixed by the package name.
  • Relative specifiers like './startup.js' or '../config.mjs'. They refer to a path relative to the location of the importing file.
  • Absolute specifiers like 'file:///opt/nodejs/config.js'. They refer directly and explicitly to a full path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant