You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Importing a file outside of the project folder causes: Emit skipped error #693
Im trying to import a file outside of the project. It's a shared file between the frontend and the server.
When i try import it it throws this error:
node_modules/ts-node/src/index.ts:370
throw new TypeError(`${relative(cwd, fileName)}: Emit skipped`)
^
TypeError: project/my_file.ts: Emit skipped
at getOutput (/Users/.../node_modules/ts-node/src/index.ts:370:15)
at Object.compile (/Users/.../node_modules/ts-node/src/index.ts:558:11)
at Module.m._compile (/Users/.../node_modules/ts-node/src/index.ts:439:43)
at Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Object.require.extensions.(anonymous function) [as .ts] (/Users/.../node_modules/ts-node/src/index.ts:442:12)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)
at Module.require (internal/modules/cjs/loader.js:650:17)
at require (internal/modules/cjs/helpers.js:20:18)
I'm able to import it from my angular project which is a sibling.
I've tried adding the file to my tsconfig under includes and files. This is what my tsconfig looks like:
I was using version 7.0.1, with typescript 2.9.2 and without any arguments so it would have been default.
I can upload an example tomorrow evening and will send you a link. I switched to compiling down with just tsc in the meantime and dont have a branch with the original ts-node setup at the moment
@bennyn Thanks for following up! Can you include the version (ts-node and typescript), your tsconfig.json and the file your tried importing? Does this compile with tsc?
I tried to use ts-node for my mocha tests which were located in ./test but my rootDir was set to ./src so the following command failed with the message "Emit skipped":
I have to admit that the error message sounded a little cryptic to me so I tried to run tsc and tsc failed too and gave me the hint that some of my TS files (the test code) is not in my rootDir, so I moved my tests from ./test to ./src/test and adjusted my mocha script:
From experimentation this appears to be happening when using ts-node --files with rootDir. I suspect related to the explanation here microsoft/TypeScript#9858
Reacted by tollinxu, Michał Weskida, AndrejAtBridebook, georgeonofrei, Marcel Michelfelder, Christopher Nowlan, Brent Thomson, Blake Raymond, Luis Casillas, Ozan Müyesseroğlu and 17 more
FYI: just in case this is useful some someone. using mocha + typescript + node, I received the same error, and it was because I had a .js file that got written next to the source .ts file. Presumably, even though ts-node isn't writing the .js files out, it detected that one was there and stopped.
Reacted by Hari Pachuveetil, Yarrow, Kaelan Cooter, Evan Lovely, Egor Elagin, Juan Jurado Capel, mdornseif, manjabes, Joren Broekema, Kyle Kovacs and 3 more
Also leaving a comment in case it is useful to someone: this error can also occur if you have "allowJs": true and have a stray *.js file that corresponds to a *.ts file in your project.
Reacted by marchand-software, waveiron, Thanasis Filippidis, tadosappo, Brent Thomson, 2qx, Fares Azzabi, earonesty, Juan Jurado Capel, MickleWen and 25 more
Also leaving a comment in case it is useful to someone: this error can also occur if you have "allowJs": true and have a stray *.js file that corresponds to a *.ts file in your project.
Any solution to this other than turning off allowJs? Would like to compile both versions (.ts & .js) and use each where appropriate. Migrating from JavaScript to TypeScript...
Reacted by Joren Broekema, Maxime Lebastard, Yashu, Oksana Boiarko, Alec Charbonneau, Markus Liebelt, 温鑫(Xin Wen) and Ejaz Karim
Also leaving a comment in case it is useful to someone: this error can also occur if you have "allowJs": true and have a stray *.js file that corresponds to a *.ts file in your project.
Any solution to this other than turning off allowJs? Would like to compile both versions (.ts & .js) and use each where appropriate. Migrating from JavaScript to TypeScript...
@marchand-software Are you saying you have two files with exactly the same filename except for the file extension? For example, foo.js and foo.ts? That's what the comment was referring to.
@cspotcode , as you put it, I'm going to correct you, the assumption is wrong and opposite to what we want 😅
In my case I do not want b to be compiled. No compilation is needed because b is already compiled. A workspace in yarn/npm workspaces is a separate package on the project with its own set of compilation scripts and config. As far as a is concerned, b should be seen as a dependency just like typescript, react, etc.
I think the piece of context missing here is that this is what the import looks like:
importbfrom'b';
There is no relative path, this is something that yarn/npm workspaces allows because in the node_modules directory a symbolic link is created.
So what we are saying is, even though the import suggests that b is referring to a package, ts-node is somehow expanding the import to the relative path the symbolic link points to, and in turn interpreting the import as a relative path, thus trying to compile something it's not supposed to.
I then understand that, with allowJs set to false, this allows node to execute the b/dist/index.js from disk without any compilation. IMHO the logic that allows this should not be attached to allowJs since I want both to be able to have js files in my a package and be able to import the symlinked version of b without it being compiled (as long as the import implies that b is a package and not a relative path to local js code).
@jeanlescure I see, I think our scope option is the right choice for you. I put an explanation at the bottom of this comment.
The expansion is actually done by node. You can see this with require.resolve('b'). I believe either TypeScript diagnostics or ts-node display the error with a relative path for readability, but node is the one resolving to an absolute path ending in dist/index.js. Node also follows symlinks by default.
ts-node's decision to compile is not based on whether the path is relative or not. It's based on TypeScript's allowJs and jsx options to decide which file extensions are compiled, and ts-node's ignore, skipIgnore, scope, and scopeDir options to decide which paths are allowed.
I can understand why your project does not want ts-node to compile other modules in the workspace, but that's not the case for all projects. Some want to write code across the monorepo and test it all via ts-node without needing to recompile anything manually. Understanding your use-case has been helpful for me, so I appreciate the detailed response.
How to use scope on your project today
scope limits ts-node to compiling files only within a given directory, scopeDir. In v10 scope and scopeDir were moved to be API-only options, and TS_NODE_SCOPE was deprecated (Release notes) However, if this option is important to your project, we can un-deprecate it and allow specifying them via tsconfig and CLI flags.
To test this today, I believe you can set env var TS_NODE_SCOPE=true and run your code. scopeDir defaults to your rootDir so it should exclude anything in the b module.
If this works for you, please let me know and we can add it to Discussions as an official recipe.
Reacted by Tobias Kullblikk, Joseph Kohlmann, Julian Meyer and Victor Machado
@cspotcode scope is exactly what I need. I've tested adding TS_NODE_SCOPE=true as you suggested, it works, if I change my rootDir.
You've hit the nail in the head because I would actually need to have separate scopeDir and rootDir. In my case I'm only using ts-node to run unit tests which are in a separate directory than src (which is my rootDir), so setting scopeDir to the directory that contains both src and unit-tests by CLI flag or tsconfig.test.json would be ideal.
I tried the ts-node option with ts-node10.1.0, unfortunately, I am still getting the throw new TypeError(${relative(cwd, fileName)}: Emit skipped) error.
This actually resolved my problem of running ts-node 10.1.0
+ "ts-node": {+ "transpileOnly": true+ },
Reacted by Vlad Kosinov
Reacted by Daniel
Reacted by Peter Butcher, Enrico, Maikon Parreira and Mitch Kuchenberg
Reacted by Jacob Page, Jorge Ampuero, Alonso García Balbuena, kim-codefresh, Jono Allen, Vinicius Kiatkoski Neves, Jonas De Kegel, Fazal, Dmitry, Peter Butcher and 7 more
I had a mixture of ts and js in a library and was hitting this issue. Since I'm using AWS amplify and importing my queries and mutations into my typescript project from a central library, I needed to change the sourcing from import { something } from '../../location', to const { something } = require('../../graphql/queries')
This actually resolved my problem of running ts-node 10.1.0
+ "ts-node": {+ "transpileOnly": true+ },
Why did this work?
It disables type checking, and emit skipped is an issue due to the type checker. It won’t compile files outside the typescript project when it’s type checking them.
Note that modern versions of ts-node entirely avoid this emit skipped error. We detect when the typechecker skips emit, and we fallback to an alternative transpilation. The end result is that users of modern ts-node never see emit skipped even when typechecking.
I have since fixed this "emit skipped" error, so recent versions of ts-node
should not have this issue. It comes from TypeScript in typechecking mode,
where TS may typecheck a file and yet refuse to emit JS for it. I now
detect when this happens and use an alternative method to emit to JS. The
result is: typechecking still works, and this error goes away.
And of course, nothing changes for transpileOnly mode: the error never
existed in that mode. So everything still works.
On Tue, Jun 21, 2022, 4:27 AM Daniel ***@***.***> wrote:
This actually resolved my problem of running ts-node 10.1.0
+ "ts-node": {+ "transpileOnly": true+ },
Why did this work?
—
Reply to this email directly, view it on GitHub
<#693 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC35OAFUIRW6OPJVDAEX73VQF4INANCNFSM4FWZAQHA>
.
You are receiving this because you modified the open/close state.Message
ID: ***@***.***>
Activity
blakeembrey commentedon Sep 25, 2018
@DustinJSilk Do you have an example that could be referenced? Also, what version of
ts-nodeand arguments are you using?DustinJSilk commentedon Sep 25, 2018
I was using version 7.0.1, with typescript 2.9.2 and without any arguments so it would have been default.
I can upload an example tomorrow evening and will send you a link. I switched to compiling down with just tsc in the meantime and dont have a branch with the original ts-node setup at the moment
bennycode commentedon Feb 18, 2019
I got the "Emit skipped" error when trying to compile TypeScript code which was not under the 'rootDir' (tsconfig.json).
blakeembrey commentedon Feb 18, 2019
@bennyn Thanks for following up! Can you include the version (
ts-nodeandtypescript), yourtsconfig.jsonand the file your tried importing? Does this compile withtsc?bennycode commentedon Feb 18, 2019
@blakeembrey I have used the latest and greatest:
My
tsconfig.jsonlooks like this:{ "compilerOptions": { "module": "commonjs", "moduleResolution": "node", "outDir": "dist", "rootDir": "src", "target": "es5" }, "exclude": [ "dist", "node_modules" ] }I tried to use
ts-nodefor my mocha tests which were located in./testbut myrootDirwas set to./srcso the following command failed with the message "Emit skipped":I have to admit that the error message sounded a little cryptic to me so I tried to run
tscandtscfailed too and gave me the hint that some of my TS files (the test code) is not in myrootDir, so I moved my tests from./testto./src/testand adjusted my mocha script:Now everything works like expected. 😃
rosskevin commentedon Feb 28, 2019
From experimentation this appears to be happening when using
ts-node --fileswithrootDir. I suspect related to the explanation here microsoft/TypeScript#9858Robert-Baindourov commentedon Aug 19, 2019
I am getting this same error within my project.
I don't even have a 'rootDir' in my tsconfig.json file
Simply tried to do a
It's strange because we have this working with esnext as the compile target and module target and then using gulp and babel as such:
But I want to skip the gulp step, and babel altogether and compile directly down to es2015 from typescript.
Robert-Baindourov commentedon Aug 19, 2019
I found a combination that worked for me, something about allowJs broke it:
tsconfig.json
vongohren commentedon Aug 22, 2019
Im getting this error when I just try to add typeRoots because of this issue: #745
I add
"typeRoots": ["./src/types","../../node_modules/@types"]I have this tsconfig:
ncoder commentedon Jan 16, 2020
FYI: just in case this is useful some someone. using mocha + typescript + node, I received the same error, and it was because I had a .js file that got written next to the source .ts file. Presumably, even though ts-node isn't writing the .js files out, it detected that one was there and stopped.
jordanrastrick commentedon Jan 20, 2020
Also leaving a comment in case it is useful to someone: this error can also occur if you have
"allowJs": trueand have a stray*.jsfile that corresponds to a*.tsfile in your project.bluelovers commentedon Jan 25, 2020
i get
Emit skippederror when"allowJs": trueis true toohttps://github.com/bluelovers/is-req-https
marchand-software commentedon Apr 15, 2020
Any solution to this other than turning off
allowJs? Would like to compile both versions (.ts&.js) and use each where appropriate. Migrating from JavaScript to TypeScript...cspotcode commentedon Apr 15, 2020
@marchand-software Are you saying you have two files with exactly the same filename except for the file extension? For example,
foo.jsandfoo.ts? That's what the comment was referring to.17 remaining items
jeanlescure commentedon May 26, 2021
@cspotcode , as you put it, I'm going to correct you, the assumption is wrong and opposite to what we want 😅
In my case I do not want
bto be compiled. No compilation is needed becausebis already compiled. A workspace in yarn/npm workspaces is a separate package on the project with its own set of compilation scripts and config. As far asais concerned,bshould be seen as a dependency just like typescript, react, etc.I think the piece of context missing here is that this is what the import looks like:
There is no relative path, this is something that yarn/npm workspaces allows because in the node_modules directory a symbolic link is created.
So what we are saying is, even though the import suggests that
bis referring to a package,ts-nodeis somehow expanding the import to the relative path the symbolic link points to, and in turn interpreting the import as a relative path, thus trying to compile something it's not supposed to.I then understand that, with
allowJsset to false, this allows node to execute theb/dist/index.jsfrom disk without any compilation. IMHO the logic that allows this should not be attached toallowJssince I want both to be able to have js files in myapackage and be able to import the symlinked version ofbwithout it being compiled (as long as the import implies thatbis a package and not a relative path to local js code).cspotcode commentedon May 26, 2021
@jeanlescure I see, I think our
scopeoption is the right choice for you. I put an explanation at the bottom of this comment.The expansion is actually done by
node. You can see this withrequire.resolve('b'). I believe either TypeScript diagnostics orts-nodedisplay the error with a relative path for readability, butnodeis the one resolving to an absolute path ending indist/index.js. Node also follows symlinks by default.ts-node's decision to compile is not based on whether the path is relative or not. It's based on TypeScript'sallowJsandjsxoptions to decide which file extensions are compiled, andts-node'signore,skipIgnore,scope, andscopeDiroptions to decide which paths are allowed.I can understand why your project does not want
ts-nodeto compile other modules in the workspace, but that's not the case for all projects. Some want to write code across the monorepo and test it all viats-nodewithout needing to recompile anything manually. Understanding your use-case has been helpful for me, so I appreciate the detailed response.How to use scope on your project today
scopelimitsts-nodeto compiling files only within a given directory,scopeDir. In v10scopeandscopeDirwere moved to be API-only options, andTS_NODE_SCOPEwas deprecated (Release notes) However, if this option is important to your project, we can un-deprecate it and allow specifying them via tsconfig and CLI flags.To test this today, I believe you can set env var
TS_NODE_SCOPE=trueand run your code.scopeDirdefaults to yourrootDirso it should exclude anything in thebmodule.If this works for you, please let me know and we can add it to Discussions as an official recipe.
jeanlescure commentedon May 26, 2021
@cspotcode scope is exactly what I need. I've tested adding
TS_NODE_SCOPE=trueas you suggested, it works, if I change myrootDir.You've hit the nail in the head because I would actually need to have separate
scopeDirandrootDir. In my case I'm only usingts-nodeto run unit tests which are in a separate directory thansrc(which is myrootDir), so settingscopeDirto the directory that contains bothsrcandunit-testsby CLI flag ortsconfig.test.jsonwould be ideal.My vote is for un-deprecate ✋🏼 😄
cspotcode commentedon May 26, 2021
Ok, excellent, I've created #1346 to add
scopeas a CLI and tsconfig option.As far as setting the appropriate
scopeDir, I believe you can add ats-nodeoverride forrootDirlike this:Will that work for you?
jeanlescure commentedon Jun 2, 2021
@cspotcode works great. Thanks 👍🏼
chenrui333 commentedon Jul 28, 2021
I tried the ts-node option with
ts-node10.1.0, unfortunately, I am still getting the throw new TypeError(${relative(cwd, fileName)}: Emit skipped) error.chenrui333 commentedon Jul 29, 2021
This actually resolved my problem of running
ts-node10.1.0brighterfrog commentedon Jan 17, 2022
I had a mixture of ts and js in a library and was hitting this issue. Since I'm using AWS amplify and importing my queries and mutations into my typescript project from a central library, I needed to change the sourcing from import { something } from '../../location', to const { something } = require('../../graphql/queries')
Update dependency ts-node to v10.5.0 (#1156)
khankid commentedon Jun 21, 2022
Why did this work?
blakeembrey commentedon Jun 26, 2022
It disables type checking, and emit skipped is an issue due to the type checker. It won’t compile files outside the typescript project when it’s type checking them.
cspotcode commentedon Jun 27, 2022
Note that modern versions of ts-node entirely avoid this emit skipped error. We detect when the typechecker skips emit, and we fallback to an alternative transpilation. The end result is that users of modern ts-node never see emit skipped even when typechecking.
cspotcode commentedon Oct 11, 2022