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

Fail to run preprocess on Windows machine #48

Closed
visma-sorinbroscaru opened this issue May 26, 2021 · 8 comments
Closed

Fail to run preprocess on Windows machine #48

visma-sorinbroscaru opened this issue May 26, 2021 · 8 comments

Comments

@visma-sorinbroscaru
Copy link

Looks like plugin fails to run preprocess on windows machines.

How to reproduce:

On Windows, with node 14.17.0 installed run following

npx degit dceddia/svelte-typescript-jest tests-fail-to-load-on-win
cd tests-fail-to-load-on-win
npm i svelte-jester@latest
npm run test

Expected:

We should see 2 passed tests.

Actual:

> svelte-app@1.0.0 test D:\_Svelte\tests-fail-to-load-on-win
> jest

internal/process/esm_loader.js:74
    internalBinding('errors').triggerUncaughtException(
                              ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'D:\_Svelte\tests-fail-to-load-on-win\node_modules\svelte\compiler' imported from D:\_Svelte\tests-fail-to-load-on-win\node_modules\svelte-jester\src\preprocess.js
Did you mean to import svelte/compiler.js?
    at finalizeResolution (internal/modules/esm/resolve.js:276:11)
    at moduleResolve (internal/modules/esm/resolve.js:699:10)
    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:810:11)
    at Loader.resolve (internal/modules/esm/loader.js:88:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:241:28)
    at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:56:40)
    at link (internal/modules/esm/module_job.js:55:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}
 1: 00007FF65D7D3E0F napi_wrap+108911
 2: 00007FF65D777E16 v8::base::CPU::has_sse+61910
 3: 00007FF65D77A859 node::OnFatalError+7273
 4: 00007FF65DFFDDCF v8::internal::Builtins::builtin_handle+321711
 5: 00007FF65DFFD364 v8::internal::Builtins::builtin_handle+319044
 6: 00007FF65DFFD657 v8::internal::Builtins::builtin_handle+319799
 7: 00007FF65DFFD4A3 v8::internal::Builtins::builtin_handle+319363
 8: 00007FF65E0D9C8D v8::internal::SetupIsolateDelegate::SetupHeap+465453
 9: 00007FF65E072092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
10: 00007FF65E09F208 v8::internal::SetupIsolateDelegate::SetupHeap+225192
11: 00007FF65E11BFDE v8::internal::SetupIsolateDelegate::SetupHeap+736638
12: 00007FF65E092458 v8::internal::SetupIsolateDelegate::SetupHeap+172536
13: 00007FF65E06FC3C v8::internal::SetupIsolateDelegate::SetupHeap+31196
14: 00007FF65DF3FB7F v8::internal::Execution::CallWasm+1839
15: 00007FF65DF3FC8B v8::internal::Execution::CallWasm+2107
16: 00007FF65DF406CA v8::internal::Execution::TryCall+378
17: 00007FF65DF20CE5 v8::internal::MicrotaskQueue::RunMicrotasks+501
18: 00007FF65DF20A40 v8::internal::MicrotaskQueue::PerformCheckpoint+32
19: 00007FF65D800B40 node::CallbackScope::~CallbackScope+672
20: 00007FF65D80090E node::CallbackScope::~CallbackScope+110
21: 00007FF65D7611D0 v8::internal::OrderedHashTable<v8::internal::OrderedHashSet,1>::NumberOfBucketsOffset+199056
22: 00007FF65D834D37 uv_timer_stop+775
23: 00007FF65D83152B uv_async_send+331
24: 00007FF65D830CBC uv_loop_init+1292
25: 00007FF65D830E5A uv_run+202
26: 00007FF65D732CD5 v8::internal::OrderedHashTable<v8::internal::OrderedHashSet,1>::NumberOfBucketsOffset+9365
27: 00007FF65D7A6F37 node::Start+311
28: 00007FF65D60677C RC4_options+339580
29: 00007FF65E5C874C v8::internal::compiler::RepresentationChanger::Uint32OverflowOperatorFor+152316
30: 00007FFF70387034 BaseThreadInitThunk+20
31: 00007FFF704C2651 RtlUserThreadStart+33

Info

Investigated a bit why this is happening, it seems that inside src/preprocess.js line 4 it attempts to import absolute path that fails on Windows machines. It looks like this is by design in NodeJs as mentioned in issue at comment

Provided solution there is to use url.pathToFileURL(pathToFile) to solve convert file path to URL file protocol for ES loader to find the file for windows as well.

Worth mentioning, older version like 1.1.15

@visma-sorinbroscaru
Copy link
Author

Oh, I see some one already managed to add same issue 2 hours before me.

@sebastianrothe
Copy link
Collaborator

Oh, I see some one already managed to add same issue 2 hours before me.

Nah, this is a different bug. Sorry about that.

@sebastianrothe
Copy link
Collaborator

Can you try it with the following devDependencies in package.json ?

"devDependencies": {
    "@babel/preset-env": "^7.14.2",
    "@rollup/plugin-commonjs": "^19.0.0",
    "@rollup/plugin-node-resolve": "^13.0.0",
    "@rollup/plugin-typescript": "^8.2.1",
    "@testing-library/jest-dom": "^5.12.0",
    "@testing-library/svelte": "^3.0.3",
    "@tsconfig/svelte": "^1.0.10",
    "@types/jest": "^26.0.23",
    "babel-jest": "^26.*",
    "jest": "^26.*",
    "rollup": "^2.50.1",
    "rollup-plugin-livereload": "^2.0.0",
    "rollup-plugin-svelte": "^7.1.0",
    "rollup-plugin-terser": "^7.0.2",
    "svelte": "^3.38.2",
    "svelte-check": "^1.6.0",
    "svelte-jester": "^1.6.0",
    "svelte-preprocess": "^4.7.3",
    "ts-jest": "^26.*",
    "tslib": "^2.2.0",
    "typescript": "^4.3.2"
  },

and then npm install and npm run test

@visma-sorinbroscaru
Copy link
Author

Same error in console as above. It still fails for me under preprocess.js:

console output!
PS D:\_Svelte\tests-fail-to-load-on-win> npm run test

> svelte-app@1.0.0 test D:\_Svelte\tests-fail-to-load-on-win
> jest

internal/process/promises.js:213
        triggerUncaughtException(err, true /* fromPromise */);
        ^

TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of NodeError
    at Socket.Writable.write (internal/streams/writable.js:285:13)
    at file:///D:/_Svelte/tests-fail-to-load-on-win/node_modules/svelte-jester/src/preprocess.js:11:32 {
code: 'ERR_INVALID_ARG_TYPE'
}
1: 00007FF66A4B3E0F napi_wrap+108911
2: 00007FF66A457E16 v8::base::CPU::has_sse+61910
3: 00007FF66A45A859 node::OnFatalError+7273
4: 00007FF66ACDDDCF v8::internal::Builtins::builtin_handle+321711
5: 00007FF66ACDD364 v8::internal::Builtins::builtin_handle+319044
6: 00007FF66ACDD657 v8::internal::Builtins::builtin_handle+319799
7: 00007FF66ACDD4A3 v8::internal::Builtins::builtin_handle+319363
8: 00007FF66ADB9C8D v8::internal::SetupIsolateDelegate::SetupHeap+465453
9: 00007FF66AD52092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
10: 00007FF66AD52092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
11: 00007FF66AD4FD4E v8::internal::SetupIsolateDelegate::SetupHeap+31470
12: 00007FF66AD4F93C v8::internal::SetupIsolateDelegate::SetupHeap+30428
13: 00007FF66AC1FAC1 v8::internal::Execution::CallWasm+1649
14: 00007FF66AC1F32F v8::internal::Execution::Call+191
15: 00007FF66AD0AEA7 v8::Function::Call+615
16: 00007FF66A4E0C04 node::CallbackScope::~CallbackScope+868
17: 00007FF66A4E090E node::CallbackScope::~CallbackScope+110
18: 00007FF66A4411D0 v8::internal::OrderedHashTable<v8::internal::OrderedHashSet,1>::NumberOfBucketsOffset+199056
19: 00007FF66A514D37 uv_timer_stop+775
20: 00007FF66A51152B uv_async_send+331
21: 00007FF66A510CBC uv_loop_init+1292
22: 00007FF66A510E5A uv_run+202
23: 00007FF66A412CD5 v8::internal::OrderedHashTable<v8::internal::OrderedHashSet,1>::NumberOfBucketsOffset+9365
24: 00007FF66A486F37 node::Start+311
25: 00007FF66A2E677C RC4_options+339580
26: 00007FF66B2A874C v8::internal::compiler::RepresentationChanger::Uint32OverflowOperatorFor+152316
27: 00007FFF70387034 BaseThreadInitThunk+20
28: 00007FFF704C2651 RtlUserThreadStart+33
FAIL  src/__tests__/hello.test.ts
● Test suite failed to run

    Command failed: node --unhandled-rejections=strict --abort-on-uncaught-exception D:\_Svelte\tests-fail-to-load-on-win\node_modules\svelte-jester\src\preprocess.js
    internal/process/promises.js:213
            triggerUncaughtException(err, true /* fromPromise */);
            ^

    TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of NodeError
        at Socket.Writable.write (internal/streams/writable.js:285:13)
        at file:///D:/_Svelte/tests-fail-to-load-on-win/node_modules/svelte-jester/src/preprocess.js:11:32 {
    code: 'ERR_INVALID_ARG_TYPE'
    }
    1: 00007FF66A4B3E0F napi_wrap+108911
    2: 00007FF66A457E16 v8::base::CPU::has_sse+61910
    3: 00007FF66A45A859 node::OnFatalError+7273
    4: 00007FF66ACDDDCF v8::internal::Builtins::builtin_handle+321711
    5: 00007FF66ACDD364 v8::internal::Builtins::builtin_handle+319044
    6: 00007FF66ACDD657 v8::internal::Builtins::builtin_handle+319799
    7: 00007FF66ACDD4A3 v8::internal::Builtins::builtin_handle+319363
    8: 00007FF66ADB9C8D v8::internal::SetupIsolateDelegate::SetupHeap+465453
    9: 00007FF66AD52092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
    10: 00007FF66AD52092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
    11: 00007FF66AD4FD4E v8::internal::SetupIsolateDelegate::SetupHeap+31470
    12: 00007FF66AD4F93C v8::internal::SetupIsolateDelegate::SetupHeap+30428
    13: 00007FF66AC1FAC1 v8::internal::Execution::CallWasm+1649
    14: 00007FF66AC1F32F v8::internal::Execution::Call+191
    15: 00007FF66AD0AEA7 v8::Function::Call+615
    16: 00007FF66A4E0C04 node::CallbackScope::~CallbackScope+868
    17: 00007FF66A4E090E node::CallbackScope::~CallbackScope+110
    18: 00007FF66A4411D0 v8::internal::OrderedHashTable<v8::internal::OrderedHashSet,1>::NumberOfBucketsOffset+199056
    19: 00007FF66A514D37 uv_timer_stop+775
    20: 00007FF66A51152B uv_async_send+331
    21: 00007FF66A510CBC uv_loop_init+1292
    22: 00007FF66A510E5A uv_run+202
    23: 00007FF66A412CD5 v8::internal::OrderedHashTable<v8::internal::OrderedHashSet,1>::NumberOfBucketsOffset+9365
    24: 00007FF66A486F37 node::Start+311
    25: 00007FF66A2E677C RC4_options+339580
    26: 00007FF66B2A874C v8::internal::compiler::RepresentationChanger::Uint32OverflowOperatorFor+152316
    27: 00007FFF70387034 BaseThreadInitThunk+20
    28: 00007FFF704C2651 RtlUserThreadStart+33


    at Socket.Writable.write (internal/streams/writable.js:285:13)
    at file:/D:/_Svelte/tests-fail-to-load-on-win/node_modules/svelte-jester/src/preprocess.js:11:32 {
        code: 'ERR_INVALID_ARG_TYPE'
    }
    1: 00007FF66A4B3E0F napi_wrap+108911
    2: 00007FF66A457E16 v8::base::CPU::has_sse+61910
    3: 00007FF66A45A859 node::OnFatalError+7273
    4: 00007FF66ACDDDCF v8::internal::Builtins::builtin_handle+321711
    5: 00007FF66ACDD364 v8::internal::Builtins::builtin_handle+319044
    6: 00007FF66ACDD657 v8::internal::Builtins::builtin_handle+319799
    7: 00007FF66ACDD4A3 v8::internal::Builtins::builtin_handle+319363
    8: 00007FF66ADB9C8D v8::internal::SetupIsolateDelegate::SetupHeap+465453
    9: 00007FF66AD52092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
    10: 00007FF66AD52092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
    11: 00007FF66AD4FD4E v8::internal::SetupIsolateDelegate::SetupHeap+31470
    12: 00007FF66AD4F93C v8::internal::SetupIsolateDelegate::SetupHeap+30428
    13: 00007FF66AC1FAC1 v8::internal::Execution::CallWasm+1649
    14: 00007FF66AC1F32F v8::internal::Execution::Call+191
    15: 00007FF66AD0AEA7 v8::Function::Call+615
    16: 00007FF66A4E0C04 node::CallbackScope::~CallbackScope+868
    17: 00007FF66A4E090E node::CallbackScope::~CallbackScope+110
    18: 00007FF66A4411D0 v8::internal::OrderedHashTable<v8::internal::OrderedHashSet,1>::NumberOfBucketsOffset+199056
    19: 00007FF66A514D37 uv_timer_stop+775
    20: 00007FF66A51152B uv_async_send+331
    21: 00007FF66A510CBC uv_loop_init+1292
    22: 00007FF66A510E5A uv_run+202
    23: 00007FF66A412CD5 v8::internal::OrderedHashTable<v8::internal::OrderedHashSet,1>::NumberOfBucketsOffset+9365
    24: 00007FF66A486F37 node::Start+311
    25: 00007FF66A2E677C RC4_options+339580
    26: 00007FF66B2A874C v8::internal::compiler::RepresentationChanger::Uint32OverflowOperatorFor+152316
    27: 00007FFF70387034 BaseThreadInitThunk+20
    28: 00007FFF704C2651 RtlUserThreadStart+33
    at Object.process (node_modules/svelte-jester/src/transformer.cjs:17:28)
    at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:463:35)
    at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:568:40)
    at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:606:25)

internal/process/promises.js:213
        triggerUncaughtException(err, true /* fromPromise */);
        ^

TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of NodeError
    at Socket.Writable.write (internal/streams/writable.js:285:13)
    at file:///D:/_Svelte/tests-fail-to-load-on-win/node_modules/svelte-jester/src/preprocess.js:11:32 {
code: 'ERR_INVALID_ARG_TYPE'
}
1: 00007FF66A4B3E0F napi_wrap+108911
2: 00007FF66A457E16 v8::base::CPU::has_sse+61910
3: 00007FF66A45A859 node::OnFatalError+7273
4: 00007FF66ACDDDCF v8::internal::Builtins::builtin_handle+321711
5: 00007FF66ACDD364 v8::internal::Builtins::builtin_handle+319044
6: 00007FF66ACDD657 v8::internal::Builtins::builtin_handle+319799
7: 00007FF66ACDD4A3 v8::internal::Builtins::builtin_handle+319363
8: 00007FF66ADB9C8D v8::internal::SetupIsolateDelegate::SetupHeap+465453
9: 00007FF66AD52092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
10: 00007FF66AD52092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
11: 00007FF66AD4FD4E v8::internal::SetupIsolateDelegate::SetupHeap+31470
12: 00007FF66AD4F93C v8::internal::SetupIsolateDelegate::SetupHeap+30428
13: 00007FF66AC1FAC1 v8::internal::Execution::CallWasm+1649
14: 00007FF66AC1F32F v8::internal::Execution::Call+191
15: 00007FF66AD0AEA7 v8::Function::Call+615
16: 00007FF66A4E0C04 node::CallbackScope::~CallbackScope+868
17: 00007FF66A4E090E node::CallbackScope::~CallbackScope+110
18: 00007FF66A4411D0 v8::internal::OrderedHashTable<v8::internal::OrderedHashSet,1>::NumberOfBucketsOffset+199056
19: 00007FF66A514D37 uv_timer_stop+775
20: 00007FF66A51152B uv_async_send+331
21: 00007FF66A510CBC uv_loop_init+1292
22: 00007FF66A510E5A uv_run+202
23: 00007FF66A412CD5 v8::internal::OrderedHashTable<v8::internal::OrderedHashSet,1>::NumberOfBucketsOffset+9365
24: 00007FF66A486F37 node::Start+311
25: 00007FF66A2E677C RC4_options+339580
26: 00007FF66B2A874C v8::internal::compiler::RepresentationChanger::Uint32OverflowOperatorFor+152316
27: 00007FFF70387034 BaseThreadInitThunk+20
28: 00007FFF704C2651 RtlUserThreadStart+33

If I go into where the issue occurs, aka preprocess.js and add a breakpoint on line 11: }).catch(err => process.stderr.write(err)) and I inspect the error I get following when checking it via vscode debugger:

Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only file and data URLs are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:'
    at Loader.defaultResolve [as _resolve] (<node_internals>/internal/modules/esm/resolve.js:782:11)
    at Loader.resolve (<node_internals>/internal/modules/esm/loader.js:88:40)
    at Loader.getModuleJob (<node_internals>/internal/modules/esm/loader.js:241:28)
    at Loader.import (<node_internals>/internal/modules/esm/loader.js:176:28)
    at importModuleDynamically (<node_internals>/internal/modules/esm/translators.js:114:35)
    at exports.importModuleDynamicallyCallback (<node_internals>/internal/process/esm_loader.js:30:14)
    at d:\_Svelte\tests-fail-to-load-on-win\node_modules\svelte-jester\src\preprocess.js:4:1
    at ModuleJob.run (<node_internals>/internal/modules/esm/module_job.js:152:23)
    at async Loader.import (<node_internals>/internal/modules/esm/loader.js:177:24)
    at async Object.loadESM (internal/process/esm_loader.js:68:5) {code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME', stack: 'Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only …loadESM (internal/process/esm_loader.js:68:5)', message: 'Only file and data URLs are supported by the…e valid file:// URLs. Received protocol 'd:''}

@sebastianrothe
Copy link
Collaborator

I will try a fix tonight. Thank you for testing.

@sebastianrothe
Copy link
Collaborator

Can you try again with the new release 1.7.0, please ?

@visma-sorinbroscaru
Copy link
Author

Works with package.json dev dependencies from above and svelte-jester at 1.7.0

@mihar-22 mihar-22 closed this as completed Jun 3, 2021
@matthieujabbour
Copy link

Hi!
Is it just me or the url.pathToFileURL(pathToFile) directive makes the svelte config import break on Linux? I'm running Node v17.6.0, and I get a MODULE_NOT_FOUND error when configuring the preprocessor in the options (my config path is resolved as file:///....). If I remove url.pathToFileURL from the dynamicImport function of transformer.cjs, everything works fine. Looks like requireing paths with the file:// is the issue.

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

4 participants