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

--emit option is not emitting files #1532

Closed
Janpot opened this issue Oct 27, 2021 · 3 comments
Closed

--emit option is not emitting files #1532

Janpot opened this issue Oct 27, 2021 · 3 comments
Labels
research Needs design work, investigation, or prototyping. Implementation uncertain. you can do this Good candidate for a pull request.

Comments

@Janpot
Copy link
Contributor

Janpot commented Oct 27, 2021

Search Terms

emit

Expected Behavior

When you run the command with --emit options, a folder .ts-node is created that contains the transpiled code.

Actual Behavior

No such folder is created

Steps to reproduce the problem

mkdir ts-node-repro
cd ts-node-repro 
npm init --yes
npm add ts-node typescript
npx tsc --init
echo 'console.log("hello")' > index.ts
npx ts-node --emit index.ts 
ls .ts-node

Result:

ls: .ts-node: No such file or directory

Specifications

ts-node v10.4.0
node v16.5.0
compiler v4.4.4
  • Operating system and version: MacOs 11.6

Related issue: #1531

@cspotcode
Copy link
Collaborator

cspotcode commented Oct 27, 2021

Looks like files are only written in the compilerHost codepath: https://github.com/TypeStrong/ts-node/blob/main/src/index.ts#L1111

This means that today, emit only works when using compilerHost & not using transpileOnly. Our swc integration falls under the transpileOnly umbrella.
https://typestrong.org/ts-node/docs/options

If someone wants to send us a PR resolving this issue, I can see two solutions:

  • a) update the docs to describe this limitation
  • b) update both transpileOnly and non-compilerHost codepaths to emit.
    • for this, you may have to do some extra work mapping from rootDir to outDir. I'm not sure.

@cspotcode cspotcode added research Needs design work, investigation, or prototyping. Implementation uncertain. you can do this Good candidate for a pull request. labels Feb 7, 2022
@cspotcode
Copy link
Collaborator

Closing as tracked by other tickets.

There's one about adding a ts-node-emit / ts-node --emit command #1175

Docs already note that --emit requires --compilerHost

@jbriales
Copy link

jbriales commented Oct 8, 2022

Even though the docs already state that --emit requires --compilerHost, as a beginner I struggled to find why this feature was not working for me.
The reason was that I had set up the config to run with --cws. After reading above, I see why that didn't work.

I'd suggest to improve the docs in this sense:

  • State that for --emit to work you cannot be using --transpileOnly (or --cws)
  • I'd clarify that the .ts-node folder will appear in the CWD. Otherwise, I confused this with some "global" output folder in the installation folder of ts-node or similar. Specially when I didn't see anything locally, because --cws prevented it :) And I had never run with --emit before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
research Needs design work, investigation, or prototyping. Implementation uncertain. you can do this Good candidate for a pull request.
Projects
None yet
Development

No branches or pull requests

3 participants