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

Support importing sideeffects #43

Open
timbrinded opened this issue Jun 5, 2024 · 1 comment
Open

Support importing sideeffects #43

timbrinded opened this issue Jun 5, 2024 · 1 comment

Comments

@timbrinded
Copy link

Importing packages with sideeffects, e.g. polyfills, gives an error in borp.

Consider the TS test:

import "core-js/stable";
import { strictEqual } from "node:assert";
import { randomInt } from "node:crypto";
import { describe, it } from "node:test";

describe("Suite 1", () => {
  it("Test 1.1", () => {
     strictEqual(true, true);
  });

  it("Test 1.2", async () => {
    const period = randomInt(0, 10) * 10;
    await new Promise((resolve) => setTimeout(resolve, period));
     strictEqual(true, true);
  });

  it("Test 1.3", async () => {
    const period = randomInt(0, 100) * 10;
    await new Promise((resolve) => setTimeout(resolve, period));
     strictEqual(true, true);
  });
});

borp gives error:

❯ pnpm borp suites/integration/test-1.test.ts
TypeScript compilation complete (1359ms)
ℹ TypeScript compilation complete (1359ms)
node:internal/process/esm_loader:34
      internalBinding('errors').triggerUncaughtException(
                                ^

Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/home/timbo/workspace/repo/test/node_modules/core-js/stable' is not supported resolving ES modules imported from /home/timbo/workspace/repo/test/dist/suites/integration/test-1.test.js
Did you mean to import "core-js/stable/index.js"?
    at finalizeResolution (node:internal/modules/esm/resolve:258:11)
    at moduleResolve (node:internal/modules/esm/resolve:924:10)
    at defaultResolve (node:internal/modules/esm/resolve:1148:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:390:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:359:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:234:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:87:39)
    at link (node:internal/modules/esm/module_job:86:36) {
  code: 'ERR_UNSUPPORTED_DIR_IMPORT',
  url: 'file:///home/timbo/workspace/repo/test/node_modules/core-js/stable'
}

Node.js v21.7.3
✖ /home/timbo/workspace/repo/test/dist/suites/integration/test-1.test.js (33.170036ms)
  'test failed'

ℹ tests 1
ℹ suites 0
ℹ pass 0
ℹ fail 1
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 35.930793

✖ failing tests:

test at dist/suites/integration/test-1.test.js:1:1
✖ /home/timbo/workspace/repo/test/dist/suites/integration/test-1.test.js (33.170036ms)
  'test failed'

whereas running via --import tsx works fine as expected.


Using tsconfig.json:

{
	"$schema": "https://json.schemastore.org/tsconfig",
	"compilerOptions": {
	  "outDir": "dist",
	  "sourceMap": true,
	  "target": "ESNext",
	  "module": "ESNext",
	  "moduleResolution": "Bundler",
	  
	  "esModuleInterop": true,
	  "strict": true,
	  "resolveJsonModule": true,
	  "removeComments": true,
	  "newLine": "lf",
	  "noUnusedLocals": true,
	  "noFallthroughCasesInSwitch": true,
	  "isolatedModules": true,
	  "forceConsistentCasingInFileNames": true,
	  "skipLibCheck": true,
	  "lib": [
		"ESNext",
		"ESNext.Disposable"
	  ],
	  "incremental": true,


	  "moduleDetection": "force",
	  "allowJs": true,

	  "verbatimModuleSyntax": true,


	  "downlevelIteration": true 
	}
  }
❯ node --version
v21.7.3
@mcollina
Copy link
Owner

mcollina commented Jun 7, 2024

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

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