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

Importing TypeScript files with ?url suffix result in the file not being transpiled #9952

Closed
7 tasks done
FezVrasta opened this issue Sep 1, 2022 · 6 comments
Closed
7 tasks done
Labels
duplicate This issue or pull request already exists

Comments

@FezVrasta
Copy link

FezVrasta commented Sep 1, 2022

Describe the bug

I'm using the ?url suffix to import a TypeScript file to use it in an AudioWorklet.

import workletUrl from './audio.worklet.ts?url';

const audioContext = new AudioContext();
audioContext.audioWorklet.addModule(workletUrl);

The problem is that Vite is not transpiling my TS file into a JS one, so the worklet fails because of it.

I think Vite should either transpile the files that it knows how to transpile, and return as URL the transpiled file, or a new option should be added to tell Vite to transpile it (e.g. ?url&transpile)

Reproduction

https://github.com/FezVrasta/vite-ts-url-import

System Info

System:
    OS: macOS 12.5.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 2.36 GB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.16.0 - ~/.nvm/versions/node/v16.16.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v16.16.0/bin/yarn
    npm: 8.11.0 - ~/.nvm/versions/node/v16.16.0/bin/npm
    Watchman: 2022.05.16.00 - /opt/homebrew/bin/watchman
  Browsers:
    Brave Browser: 104.1.42.97
    Chrome: 105.0.5195.52
    Firefox: 103.0.1
    Safari: 15.6.1
  npmPackages:
    vite: ^3.0.7 => 3.0.9 

Used Package Manager

npm

Logs

No response

Validations

@bluwy
Copy link
Member

bluwy commented Sep 4, 2022

Looks like a bug that it should be transpiled by default, you can workaround it by using new URL('./path/to/file.ts', import.meta.url). Though for AudioWorklet, even if ?url works you might hit #9606

@sapphi-red
Copy link
Member

I think this is related to #6757, #2522 (comment).

@FezVrasta
Copy link
Author

Looks like a bug that it should be transpiled by default, you can workaround it by using new URL('./path/to/file.ts', import.meta.url). Though for AudioWorklet, even if ?url works you might hit #9606

Thanks for the reply, using new URL doesn't seem to work, the resulting URL returns 404.

@FezVrasta
Copy link
Author

I think this is related to #6757, #2522 (comment).

The second looks definitely related, I'm not sure about the first, it seems to be a different problem?

@cedeber
Copy link
Contributor

cedeber commented Sep 20, 2022

There is definitely a regression somewhere. Using import.meta.url results in importing my .ts files as video/m2ts instead of TypeScript.

@sapphi-red
Copy link
Member

Duplicate of #6979

@sapphi-red sapphi-red marked this as a duplicate of #6979 Oct 17, 2022
@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale Oct 17, 2022
@sapphi-red sapphi-red added duplicate This issue or pull request already exists and removed pending triage labels Oct 17, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Nov 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

4 participants