简体   繁体   English

TypeScript:tsc.exe --execute:错误找不到模块

[英]TypeScript: tsc.exe --execute: Error cannot find module

I have the following directory setup: 我有以下目录设置:

/app/ioc.ts
/tests/test.ts

I'm in the tests directory. 我在测试目录中。 The contents of app/ioc.ts are unimportant, but the contents of tests/test.ts are: app/ioc.ts的内容并不重要,但是tests/test.ts的内容是:

import IOC = module('../app/ioc');
var container = new IOC.Container();

If I compile this like so: 如果我这样编译:

tsc test.ts

Then run it like so: 然后像这样运行它:

node test

All's good! 一切都好! The file runs without errors. 该文件运行没有错误。 However! 然而! If I run it like this: 如果我这样运行:

tsc -e test.ts

I get the following error: 我收到以下错误:

module.js:340
    throw err;
          ^
Error: Cannot find module '../app/ioc'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (D:/dropbox/work/sandbox/Prototyping/TypeScript/tests/test.js:1:73)
    at Module._compile (module.js:456:26)
    at Object.run (C:\Users\nathan\AppData\Roaming\npm\node_modules\typescript\bin\tsc.js:56041:30)
    at BatchCompiler.run (C:\Users\nathan\AppData\Roaming\npm\node_modules\typescript\bin\tsc.js:56563:29)
    at BatchCompiler.batchCompile (C:\Users\nathan\AppData\Roaming\npm\node_modules\typescript\bin\tsc.js:56795:26)
    at Object.<anonymous> (C:\Users\nathan\AppData\Roaming\npm\node_modules\typescript\bin\tsc.js:56908:7)

Any ideas? 有任何想法吗?

Your code is fine. 您的代码很好。 The -e flag is being removed from tsc, partly because it doesn't play nicely with this sort of scenario. -e标志已从tsc中删除,部分原因是它在这种情况下不能很好地发挥作用。 Executing arbitrary JS in the context of the compiler process turns out to not be a good idea. 在编译器过程的上下文中执行任意JS并不是一个好主意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM