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

cjs conflict with https://deno.land/[email protected]/hash/mod.ts #6995

Closed
aaronwlee opened this issue Aug 9, 2020 · 9 comments
Closed
Labels
bug Something isn't working correctly cli related to cli/ dir

Comments

@aaronwlee
Copy link

aaronwlee commented Aug 9, 2020

This is a strange bug.

When loading both https://deno.land/[email protected]/hash/mod.ts and some cjs files, deno checks the type of cjs.

export { createHash } from "https://deno.land/[email protected]/hash/mod.ts";
import {} from "./cjsTest.cjs"
error: TS2339 [ERROR]: Property 'test' does not exist on type '{}'.
  return exports.test;
                 ~~~~
    at file:///C:/Users/stone/OneDrive/%EB%B0%94%ED%83%95%20%ED%99%94%EB%A9%B4/%EC%83%88%20%ED%8F%B4%EB%8D%94/postgres/cjsTest.cjs:4:18

Windows 10 v2004 - X
WSL (Ubuntu bionic) - X
macOS Catalina - X

@kitsonk
Copy link
Contributor

kitsonk commented Aug 9, 2020

Duplicate of #6176

@aaronwlee
Copy link
Author

@kitsonk Hi, I don't think it's been related. This cjs file loading normally working fine, but this issue happens only with this hash module.

@lucacasonato
Copy link
Member

@aaronwlee It happens if any sibling of this cjs module is a TypeScript file, not just std/hash right? In that case it is a duplicate of #6176.

@aaronwlee
Copy link
Author

aaronwlee commented Aug 9, 2020

@lucacasonato

Sorry to confuse y'all. Ok, I think it's a more complex bug...

I thought only the combination of the hash module and cjs was a problem.
But if it's a cjs loading issue then the sample code below shouldn't work.

import { emptyDir, emptyDirSync } from "https://deno.land/std/fs/mod.ts";
// or any other modules except hash

import babelCore from "https://jspm.dev/@babel/core"; // this returns cjs.

Simply run this code is working perfectly fine.
And, at this level, we can assume that babelCore is recognized as a js module rather than a cjs.
Even if babelCore is a bundle of cjs files.

An unknown bug occurs in the sample code below.

This is a sample code that added a hash module.

import { emptyDir, emptyDirSync } from "https://deno.land/std/fs/mod.ts";
export { createHash } from "https://deno.land/[email protected]/hash/mod.ts";

import babelCore from "https://jspm.dev/@babel/core";

Run this code returns 10651 type errors...
I don't know exactly, but due to the loading of the hash module, babelCore is suddenly recognized as a party of typescript.
It's only happened with std/hash

@aaronwlee
Copy link
Author

temp solution.

// tsconfig.json
{
  "compilerOptions": {
    "allowJs": false,
    "lib": ["ESNext", "DOM", "dom.iterable", "deno.unstable", "deno.ns"],
  }
}

@bartlomieju bartlomieju added bug Something isn't working correctly cli related to cli/ dir labels Aug 27, 2020
@MichaelBauerLHIND
Copy link

I have the same Problem with the combo
import { Handlebars } from "https://deno.land/x/[email protected]/mod.ts";
and
import { createHash } from "https://deno.land/[email protected]/hash/mod.ts";

but if you use a hash module directly
import { Sha1 } from "https://deno.land/[email protected]/hash/sha1.ts";
it works

maybe its a problem with the wasm module
import { Hash } from "./_wasm/hash.ts";

the tsconfig.json does't help

@kitsonk
Copy link
Contributor

kitsonk commented Nov 2, 2020

@MichaelBauerLHIND what version of deno are you using?

It appears that https://deno.land/x/[email protected]/mod.ts has some issues independent of anything else, and probably should open an issue with the package maintain, because it is importing an untyped version of handlebars. I am getting the following with 1.5.1:

error: TS2339 [ERROR]: Property 'registerHelper' does not exist on type '{}'.
        HandlebarsJS.registerHelper(helperKey, this.config.helpers[helperKey])
                     ~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/mod.ts:43:22

TS2339 [ERROR]: Property 'compile' does not exist on type '{}'.
    const template = HandlebarsJS.compile(source, this.config!.compilerOptions);
                                  ~~~~~~~
    at https://deno.land/x/[email protected]/mod.ts:96:35

TS2339 [ERROR]: Property 'registerPartial' does not exist on type '{}'.
      HandlebarsJS.registerPartial(templateName, source);
                   ~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/mod.ts:115:20

Found 3 errors.

That has nothing to do with this issue. I don't even need to import createHash.

The API also uses --unstable as well, if I omit --unstable I get 19 errors. None of them related to createHash.

@kitsonk
Copy link
Contributor

kitsonk commented Nov 2, 2020

@aaronwlee I think the underlying issue is resolved in 1.5.1 (it was/is a duplicate of #6176), but there seems to be another issue related specifically the https://jspm.dev/@babel/core package. There is a problem that with allowJs TypeScript "helpfully" tries to transpile any CommonJS modules to ESM and it is choking on a module during the emit. I have had a little bit better luck with https://cdn.skypack.dev/@babel/core, but that seems to be triggering another strange TypeScript error.

@lucacasonato
Copy link
Member

No objections to it being resolved. If you do still encounter this, please re-open.

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

No branches or pull requests

5 participants