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

Weird import default error #86

Closed
1 task
wmelton opened this issue Aug 19, 2022 · 5 comments
Closed
1 task

Weird import default error #86

wmelton opened this issue Aug 19, 2022 · 5 comments
Labels

Comments

@wmelton
Copy link

wmelton commented Aug 19, 2022

Bug description

When utilizing the @tensorflow-models/universal-sentence-encoder npm package, we experienced a weird bug that went unnoticed until deployment to production. We utilized esmo by @antfu for all local dev development on a typescript express api.

Using: import use from '@tensorflow-models/universal-sentence-encoder' in our script worked perfectly locally. After building (ts->cjs/esm) and deploying to production, we got errors essentially saying many of the module functions were undefined.

After messing with it, we discovered that updating the import statement to:
import * as use from '@tensorflow-models/universal-sentence-encoder'
fixed the issue both when running uncompiled ts from the cli and post-build js in our production environment.

I'm not familiar enough with the build process ts->cjs/esm to understand the details of what could cause this. However, on the face of it, it does seem to me that if an import would fail post-compile, then tsx should fail too.

Reproduction

  1. Build a test script that utilized import use from '@tensorflow-models/universal-sentence-encoder'
  2. Build ts code using tsc -p ./tsconfig.json
  3. Try to load the model: model = await use.load() in the resulting code
  4. `...undefined (reading 'load')
  5. Update import = import * as use from '@tensorflow-models/universal-sentence-encoder'
  6. repeat steps 2-3. Works.

Environment

System:
    OS: macOS 12.3.1
    CPU: (8) x64 Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
    Memory: 1.11 GB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.14.2 - ~/.nvm/versions/node/v16.14.2/bin/node
    npm: 8.16.0 - ~/.nvm/versions/node/v16.14.2/bin/npm
Packages:
├── @aws-sdk/client-s3@3.112.0
├── @datadog/datadog-api-client@1.0.0
├── @sentry/node@6.19.7
├── @sentry/tracing@6.19.7
├── @tensorflow-models/universal-sentence-encoder@1.3.3
├── @tensorflow/tfjs-node@3.18.0
├── @tsconfig/node16@1.0.3
├── @types/connect-datadog@0.0.6
├── @types/cookie-parser@1.4.3
├── @types/cors@2.8.12
├── @types/express@4.17.13
├── @types/jest@27.5.2
├── @types/mysql@2.15.21
├── @types/node@17.0.45
├── @types/sharp@0.30.4
├── @types/xml2js@0.4.11
├── @types/yup@0.29.14
├── @typescript-eslint/eslint-plugin@5.28.0
├── @typescript-eslint/parser@5.28.0
├── axios@0.26.1
├── bumpp@7.2.0
├── conventional-changelog-cli@2.2.2
├── cookie-parser@1.4.6
├── cors@2.8.5
├── dateformat@4.6.3
├── dd-trace@2.9.1
├── dotenv@16.0.1
├── eslint-config-prettier@8.5.0
├── eslint-import-resolver-typescript@2.7.1
├── eslint-plugin-eslint-comments@3.2.0
├── eslint-plugin-import@2.26.0
├── eslint-plugin-jsonc@2.3.0
├── eslint-plugin-unicorn@41.0.1
├── eslint@8.17.0
├── esno@0.14.1
├── express@4.18.1
├── form-data@4.0.0
├── google-libphonenumber@3.2.28
├── html-tablify@1.1.1
├── jest@27.5.1
├── mailgun.js@5.2.2
├── mkdir-recursive@0.4.0
├── mysql@2.18.1
├── nanoid@3.3.4
├── nodemon@2.0.19
├── request-ip@2.2.0
├── rimraf@3.0.2
├── sharp@0.30.7
├── shelljs@0.8.5
├── stripe-money-format@1.0.10
├── stripe@8.222.0
├── ts-jest@27.1.5
├── ts-node@10.8.1
├── tsc-watch@4.6.2
├── typescript@4.7.4
├── unbuild@0.7.4
├── util@0.12.4
├── winston-sentry@0.2.1
├── winston@3.8.1
├── xlsx@0.18.5
├── xml2js@0.4.23
└── yup@1.0.0-beta.4

Can you contribute a fix?

  • I’m interested in opening a pull request for this issue.
@wmelton wmelton added bug Something isn't working pending triage labels Aug 19, 2022
@privatenumber
Copy link
Owner

privatenumber commented Aug 20, 2022

Thanks for the issue.

I can't reproduce though. Can you link to a repository containing a minimal reproduction?

@wmelton
Copy link
Author

wmelton commented Aug 20, 2022

Yeah no problem, I will put that together and update with a link.

@privatenumber
Copy link
Owner

Will re-open once reproduction is provided

TehShrike added a commit to TehShrike/tsx_issue_86_repro that referenced this issue Jan 30, 2023
@TehShrike
Copy link

I have a minimal reproduction at https://github.com/TehShrike/tsx_issue_86_repro

I ran into the issue importing TypeScript files from a module.

@privatenumber
Copy link
Owner

Thanks for the reproduction @TehShrike

Your issue is the same as #38

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants