TypeScript Version: 2.8.0-dev.20180130
Search Terms:
Code
// A *self-contained* demonstration of the problem follows...
// Test this by running `tsc` on the command-line, rather than through another build tool such as Gulp, Webpack, etc.
import a from 'a';
import b from 'b';
a();
b();
// ...
Expected behavior:
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "a", "b"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const a = require('a');
const b = require('b');
a();
b();
// ...
});
Actual behavior:
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
a();
b();
// ...
});
Playground Link:
Related Issues:
I find in watch mode, dependencies will missing, but it is fine not in watch mode, only in watch mode. I tried to write a test but I find simple test is fine even in watch mode.
I also tried latest version, it is fine in watch mode, too.
Anyone meet same issue?
the test code just is a simple demo, cause i really could not write it. just because new issue requires that.
I am unable to reproduce this locally with just this file.. can you share more context.
The more info helpful in investigating this would be what are the contents of modules a and b are.. What are the compiler options you are using and which edit is causing the incorrect input or is it any kind of edit that results in incorrect output. Also it would be helpful if you run your program with --listFiles and --listEmittedFiles with and without --watch option to diagnose if some files are being missed in the program with --watch..
still do not get a repro for this file. can you share a sample project? we would be happy to receive it by email if you would rather not share it on github. also we would be open to signing an NDA to get access to the project.
Hi, I am also find this strange behavior which I cannot reproduce. It may happen sometimes in --watchmode after update to 2.7.1
i think this might be fixed by #21524
@sheetalkamat Yes, it's ok now.
I think it is still an issue with even 2.7.1 and 2.7.2. Some of my imports are going missing.
Simply, keeping a reference to the import seems to work fine.
I think it is still an issue with even 2.7.1 and 2.7.2.
2.7.2 has not be published yet. have you tried with typescript@next?
How would that diagnostics change impact imports sometimes being left out of the generated .js files?
@mhegazy for my project, this bug was addressed in build 2.8.0-dev.20180204, but seems to have come back yesterday when I upgraded to 2.8.0-dev.20180209. With 0209 I might only get 2 rebuilds before the error returns (and I have to restart the tsc process to recover).
@mceachen can you share more details?
Actually, it turns out my issue is slightly different than this--tsc -w says that some import lines in my typescript are unused, but they are. The imports it complains about are deterministic. If I bounce tsc the error goes away. My source tree is closed, though. Is there an issue tracking this yet? If so, I'll delete this comment and my prior, and move them there.
I ran into the same issue with tsc v2.7.1 - when I invoked 'tsc -w' the first time, it worked fine. After editing a file, the imports were removed.
I recreated this issue using a small express project that I've attached in a zip file. Unzip it, call npm i to install the dependencies, and press F5 to launch the app (in vs code), and it works just fine. After changing the welcome message in routes.ts file, however, it crashes. See below for details:
routes.ts
import { Application } from 'express';
import * as express from 'express';
export const setupRoutes = (app: Application) => {
const router = express.Router();
router.get('/', (req, res) => res.send('Hello, world'));
app.use('/', router);
};
Becomes after initial compile (tsc -w):
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
}
Object.defineProperty(exports, "__esModule", { value: true });
const express = __importStar(require("express"));
exports.setupRoutes = (app) => {
const router = express.Router();
router.get('/', (req, res) => res.send('Hello, world'));
app.use('/', router);
};
//# sourceMappingURL=routes.js.map
And after I change 'world' to 'you', I end up with:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setupRoutes = (app) => {
const router = express.Router();
router.get('/', (req, res) => res.send('Hello you'));
app.use('/', router);
};
//# sourceMappingURL=routes.js.map
Causing the application to throw a 'ReferenceError: express is not defined'
Same thing is happening to us. Was quite annoying to track down since we initially assumed it to be an issue with rollup. Thankfully it is being tracked.
Any idea on a release ? I am not sure going to next is very helpful as that also includes lots of non properly tested code I assume
@erikvullings i have verified that the issue you have reported is fixed with typescript@next
@sheetalkamat yep, it is fixed with typescript@next. Thanks for verifying!
We were just about to upgrade to 2.7.1 when I hit this bug. typescript@next fixes it, but I don't want to upgrade our production build to a nightly. It would be great to see 2.7.2 soon since the fix was merged a couple of weeks ago. 鉂わ笍
cc @mhegazy @DanielRosenwasser for 2.7.2
should be out later today.
Most helpful comment
should be out later today.