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

npm:aws-cdk init throws TypeError (windows only) #2916

Closed
GJZwiers opened this issue Nov 19, 2022 · 9 comments · Fixed by #3168
Closed

npm:aws-cdk init throws TypeError (windows only) #2916

GJZwiers opened this issue Nov 19, 2022 · 9 comments · Fixed by #3168
Labels
bug Something isn't working windows

Comments

@GJZwiers
Copy link
Contributor

GJZwiers commented Nov 19, 2022

deno run -A npm:aws-cdk init --language typescript

Applying project template app for typescript
TypeError [ERR_INVALID_ARG_TYPE]" argument must be of type number. Received undefined
    at __node_internal_ (https://deno.land/std@0.165.0/node/internal/validators.mjs:112:15)
    at parseFileMode (https://deno.land/std@0.165.0/node/internal/validators.mjs:49:3)
    at Object.chmod (https://deno.land/std@0.165.0/node/_fs/_fs_chmod.ts:8:12)
    at Object.chmod (file:///C:/Users/GJZwiers/AppData/Local/deno/npm/registry.npmjs.org/node_modules/graceful-fs/polyfills.js:252:19)l-fs/polyfills.js:252:19)                                                                                     /lib/copy/copy.js:131:13)
    at setDestMode (file:///C:/Users/GJZwiers/AppData/Local/deno/npm/registry.npmjs.org/node_modules/fs-extray.js:98:12/lib/copy/copy.js:131:13)                                                                                     fs.js:186:16
    at file:///C:/Users/GJZwiers/AppData/Local/deno/npm/registry.npmjs.org/node_modules/fs-extra/lib/copy/copy.js:98:12
    at file:///C:/Users/GJZwiers/AppData/Local/deno/npm/registry.npmjs.org/node_modules/graceful-fs/graceful-fs.js:186:16
    at https://deno.land/std@0.165.0/node/_fs/_fs_common.ts:230:31
    at https://deno.land/std@0.165.0/node/_fs/_fs_copy.ts:30:49
deno --version

deno 1.28.1 (release, x86_64-pc-windows-msvc)
v8 10.9.194.1
typescript 4.8.3

Edit: Only happens on Windows

@GJZwiers GJZwiers changed the title npm:aws-cdk init throws TypeError npm:aws-cdk init throws TypeError (windows only) Nov 19, 2022
@bartlomieju bartlomieju transferred this issue from denoland/deno Nov 20, 2022
@bartlomieju bartlomieju added bug Something isn't working node labels Nov 20, 2022
@cjihrig
Copy link
Contributor

cjihrig commented Nov 21, 2022

Since this is Windows only, would you care to help debug or fix, @GJZwiers ?

@GJZwiers
Copy link
Contributor Author

I can do some debugging! Is there a way to make my local deno binary/cargo build work with my local copy of std, so I can test some changes?

@cjihrig
Copy link
Contributor

cjihrig commented Nov 22, 2022

Is there a way to make my local deno binary/cargo build work with my local copy of std, so I can test some changes?

Yep! Here is what I use:

DENO_NODE_COMPAT_URL='file:///path/to/your/std/' /path/to/cli/deno run -A --unstable your_script.js

@GJZwiers
Copy link
Contributor Author

The issue seems to be that the mode parameter passed to chmod function is null and no default value def is set in parseFileMode, causing an assignment to undefined. Deeper in the call stack I found that mode is set to 0 but when it goes through the node compat layer it changes to null somewhere. This happens in an internal node_modules folder that is maybe created on the fly (because it doesn't exist in my filesystem)?

A potential fix for this issue could be to pass a value for def in the chmod function (although the code will still throw with another error because it then calls Deno.chmod which is not supported on Windows at the moment (denoland/deno#4357)).

@cjihrig
Copy link
Contributor

cjihrig commented Nov 23, 2022

Thanks for taking a look. Interestingly, Node does not pass a default value to here either.

@GJZwiers
Copy link
Contributor Author

GJZwiers commented Feb 4, 2023

Based on denoland/deno#17841 I made a simpler reproduction for the error:

import * as fs from "npm:fs-extra";

await fs.copy("foo.js", "bar.js");

@PolarETech
Copy link
Contributor

In fs-extra, file permission is also copied when copying a file.

https://github.com/jprichardson/node-fs-extra/blob/f3a7f0beeb5858c628b10010ad819c813c7f3565/lib/copy/copy.js#L102
https://github.com/jprichardson/node-fs-extra/blob/f3a7f0beeb5858c628b10010ad819c813c7f3565/lib/copy/copy.js#L134

The mode of the source file is got by fs.stat or fs.lstat.

https://github.com/jprichardson/node-fs-extra/blob/f3a7f0beeb5858c628b10010ad819c813c7f3565/lib/copy/copy.js#L67

With Node.js we can get the mode value of the file, even on Windows, but with Deno it returns null.
This is why the mode value passed to the chmod function is null.

@PolarETech
Copy link
Contributor

fs.stat and fs.lstat use Deno.stat and Deno.lstat.

https://github.com/denoland/deno_std/blob/1cda9238eaa24b26fd34e1d5963906ed1bcdd301/node/_fs/_fs_stat.ts#L273
https://github.com/denoland/deno_std/blob/1cda9238eaa24b26fd34e1d5963906ed1bcdd301/node/_fs/_fs_lstat.ts#L40

It would be nice if functions like Deno.stat would support for the mode property on Windows, but is this difficult due to Rust's std::fs reasons?

A workaround might be to ignore parseFileMode as well, since Deno.chmod is not available on Windows anyway.

https://github.com/denoland/deno_std/blob/1cda9238eaa24b26fd34e1d5963906ed1bcdd301/node/_fs/_fs_chmod.ts#L9-L27

@kt3k
Copy link
Member

kt3k commented Feb 6, 2023

skipping parseFileMode on windows makes sense to me.

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

Successfully merging a pull request may close this issue.

5 participants