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

fix: cjs export rewritten to invalid identifier #21853

Merged
merged 2 commits into from
Jan 8, 2024
Merged

Conversation

marvinhagemeister
Copy link
Contributor

Fixes #21836

Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@marvinhagemeister marvinhagemeister enabled auto-merge (squash) January 8, 2024 17:31
@marvinhagemeister marvinhagemeister merged commit 040fdee into main Jan 8, 2024
14 checks passed
@marvinhagemeister marvinhagemeister deleted the cjs-identifier branch January 8, 2024 17:50
@gplanansky
Copy link

thanks for such a quick fix. However it didn't work for me.

Per instructions for MacOS m1/m2, I built the subsequent canary, with the fix in ext/node/analyze.rs .
The build worked fine, no hitches -- credit to you all for that!

Unfortunately looks like "deno --version" stopped giving the canary hash recently, so that useful info is no longer available by command line. I don't know how else to determine it? But here's a snippet from the source to verify that analyze.rs has the current fix:

fn is_valid_var_decl(name: &str) -> bool {
    // it's ok to be super strict here
    if name.is_empty() {
      return false;
    }

    if let Some(first) = name.chars().next() {
      if !first.is_ascii_alphabetic() && first != '_' && first != '$' {
        return false;
      }
    }

And here is the same import failure result. It works for pl, still fails for Plotly.

$ ~/.deno/bin/deno 
Deno 1.39.2
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.

> import * as pl from 'npm:nodejs-polars';
undefined

> import Plotly from "npm:[email protected]"
Uncaught SyntaxError: Invalid or unexpected token at file:///Users/george/jd/deno/node_modules/.deno/[email protected]/node_modules/plotly.js-dist/plotly.js:828:14
    at async <anonymous>:1:52

@bartlomieju
Copy link
Member

@gplanansky so it works if you build from source but not if you deno upgrade? If so that's expected. We don't have canary builds for M1/M2.

@gplanansky
Copy link

@bartlomieju

  1. My mistake ~/deno/bin/deno was Not the result of my build. Because "deno --version" no longer gives the canary hash, I could not verify.

  2. it still does not work.

    I just rebuilt deno, capturing the commit hash: GIT_COMMIT_HASH=741afc4b94427588c628925fef464623d373430f

git clone --recurse-submodules https://github.com/denoland/deno.git

$ cd deno
$ cargo build -vv > /tmp/cargo-build.txt
  Downloaded deno_unsync v0.3.2
  Downloaded deno_ops v0.120.0
  Downloaded serde_v8 v0.153.0
[...]
CARGO=/Users/george/.rustup/toolchains/1.75.0-aarch64-apple-darwin/bin/cargo CARGO_BIN_NAME=deno CARGO_CRATE_NAME=deno CARGO_MANIFEST_DIR=/Users/george/deno/deno-dev/deno/cli CARGO_PKG_AUTHORS='the Deno authors' CARGO_PKG_DESCRIPTION='Provides the deno executable' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE=MIT CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=deno CARGO_PKG_README=README.md CARGO_PKG_REPOSITORY='https://github.com/denoland/deno' CARGO_PKG_RUST_VERSION='' CARGO_PKG_VERSION=1.39.2 CARGO_PKG_VERSION_MAJOR=1 CARGO_PKG_VERSION_MINOR=39 CARGO_PKG_VERSION_PATCH=2 CARGO_PKG_VERSION_PRE='' CARGO_PRIMARY_PACKAGE=1 DYLD_FALLBACK_LIBRARY_PATH='/Users/xxx/deno/deno-dev/deno/target/debug/deps:/Users/george/.rustup/toolchains/1.75.0-aarch64-apple-darwin/lib:/Users/xxx.rustup/toolchains/1.75.0-aarch64-apple-darwin/lib:/Users/xxx/lib:/usr/local/lib:/usr/lib' GIT_COMMIT_HASH=741afc4b94427588c628925fef464623d373430f 

If I am doing it right, deno still fails importing plotly:

$ target/debug/deno
Deno 1.39.2
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.

> import * as pl from 'npm:nodejs-polars';
undefined

> import Plotly from "npm:[email protected]"
Uncaught TypeError: Cannot read properties of undefined (reading 'navigator')
    at Object.__webpack_modules__.71828.lib.getFirefoxVersion (file:///Users/xxx/Library/Caches/deno/npm/registry.npmjs.org/plotly.js-dist/2.27.1/plotly.js:26820:49)
    at Object.71828 (file:///Users/xxx/Library/Caches/deno/npm/registry.npmjs.org/plotly.js-dist/2.27.1/plotly.js:27396:26)
    at __webpack_require__ (file:///Users/xxx/Library/Caches/deno/npm/registry.npmjs.org/plotly.js-dist/2.27.1/plotly.js:224454:42)
    at Object.98847 (file:///Users/xxx/Library/Caches/deno/npm/registry.npmjs.org/plotly.js-dist/2.27.1/plotly.js:26:11)
    at __webpack_require__ (file:///Users/xxx/Library/Caches/deno/npm/registry.npmjs.org/plotly.js-dist/2.27.1/plotly.js:224454:42)
    at Object.8729 (file:///Users/xxx/Library/Caches/deno/npm/registry.npmjs.org/plotly.js-dist/2.27.1/plotly.js:23241:1)
    at __webpack_require__ (file:///Users/xxx/Library/Caches/deno/npm/registry.npmjs.org/plotly.js-dist/2.27.1/plotly.js:224454:42)
    at Object.19548 (file:///Users/xxx/Library/Caches/deno/npm/registry.npmjs.org/plotly.js-dist/2.27.1/plotly.js:213:18)
    at __webpack_require__ (file:///Users/xxx/Library/Caches/deno/npm/registry.npmjs.org/plotly.js-dist/2.27.1/plotly.js:224454:42)
    at Object.27909 (file:///Users/xxx/Library/Caches/deno/npm/registry.npmjs.org/plotly.js-dist/2.27.1/plotly.js:343:14)
> 

@bartlomieju
Copy link
Member

@gplanansky I see what you mean. The error you are getting is now completely different so it's a completely different bug now. Could you open a new issue about it?

@gplanansky
Copy link

@bartiomieju deno import Plotly error: Cannot read properties of undefined (reading 'navigator') #21871

bartlomieju pushed a commit that referenced this pull request Jan 12, 2024
<!--
Before submitting a PR, please read https://deno.com/manual/contributing

1. Give the PR a descriptive title.

  Examples of good title:
    - fix(std/http): Fix race condition in server
    - docs(console): Update docstrings
    - feat(doc): Handle nested reexports

  Examples of bad title:
    - fix #7123
    - update docs
    - fix bugs

2. Ensure there is a related issue and it is referenced in the PR text.
3. Ensure there are tests that cover the changes.
4. Ensure `cargo test` passes.
5. Ensure `./tools/format.js` passes without changing files.
6. Ensure `./tools/lint.js` passes.
7. Open as a draft PR if your work is still in progress. The CI won't
run
   all steps, but you can add '[ci]' to a commit message to force it to.
8. If you would like to run the benchmarks on the CI, add the 'ci-bench'
label.
-->

Fixes #21836
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

Successfully merging this pull request may close these issues.

Syntax error with valid JS code
4 participants