Skip to content

Error when compiling with gulp-typescript. #564

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

Closed
mirthlaj opened this issue Feb 18, 2018 · 6 comments
Closed

Error when compiling with gulp-typescript. #564

mirthlaj opened this issue Feb 18, 2018 · 6 comments

Comments

@mirthlaj
Copy link

When compiling with gulp-typescript I get an error.
With tsc everything works as expected and no errors are shown.

I am using [email protected] and I also tried version 3.0.2 as suggested here ##421.

Expected behavior:
compiled typescript files
Actual behavior:

[18:20:21] Starting 'default'...
D:/Code/NodeJS/typescript-template/node_modules/@types/bluebird/index.d.ts(468,33): error TS2304: Cannot find name 'Map'.
D:/Code/NodeJS/typescript-template/node_modules/@types/bluebird/index.d.ts(468,72): error TS2304: Cannot find name 'Map'.
D:/Code/NodeJS/typescript-template/node_modules/@types/bluebird/index.d.ts(747,39): error TS2304: Cannot find name 'Map'.
D:/Code/NodeJS/typescript-template/node_modules/@types/bluebird/index.d.ts(747,69): error TS2304: Cannot find name 'Map'.
D:/Code/NodeJS/typescript-template/node_modules/@types/bluebird/index.d.ts(747,107): error TS2304: Cannot find name 'Map'.
D:/Code/NodeJS/typescript-template/src/routes/root.ts(3,7): error TS4023: Exported variable 'router' has or is using name 'Router' from external module "D:/Code/NodeJS/typescript-template/node_modules/@types/express-serve-static-core/index" but cannot be named.
D:/Code/NodeJS/typescript-template/src/routes/users.ts(3,7): error TS4023: Exported variable 'router' has or is using name 'Router' from external module "D:/Code/NodeJS/typescript-template/node_modules/@types/express-serve-static-core/index" but cannot be named.
D:/Code/NodeJS/typescript-template/src/server.ts(6,7): error TS4023: Exported variable 'app' has or is using name 'Express' from external module "D:/Code/NodeJS/typescript-template/node_modules/@types/express-serve-static-core/index" but cannot be named.
TypeScript: 5 semantic errors
TypeScript: 3 declaration errors
TypeScript: 3 emit errors
TypeScript: emit failed
D:/Code/NodeJS/typescript-template/node_modules/@types/bluebird/index.d.ts(468,33): error TS2304: Cannot find name 'Map'.
D:/Code/NodeJS/typescript-template/node_modules/@types/bluebird/index.d.ts(468,72): error TS2304: Cannot find name 'Map'.
D:/Code/NodeJS/typescript-template/node_modules/@types/bluebird/index.d.ts(747,39): error TS2304: Cannot find name 'Map'.
D:/Code/NodeJS/typescript-template/node_modules/@types/bluebird/index.d.ts(747,69): error TS2304: Cannot find name 'Map'.
D:/Code/NodeJS/typescript-template/node_modules/@types/bluebird/index.d.ts(747,107): error TS2304: Cannot find name 'Map'.
D:/Code/NodeJS/typescript-template/node_modules/pg-promise/typescript/pg-promise.d.ts(5,27): error TS2497: Module '"D:/Code/NodeJS/typescript-template/node_modules/pg-promise/typescript/ext-promise"' resolves to a non-module entity and cannot be imported using this construct.
src\routes\root.ts(3,7): error TS4023: Exported variable 'router' has or is using name 'Router' from external module "D:/Code/NodeJS/typescript-template/node_modules/@types/express-serve-static-core/index" but cannot be named.
src\routes\users.ts(3,7): error TS4023: Exported variable 'router' has or is using name 'Router' from external module "D:/Code/NodeJS/typescript-template/node_modules/@types/express-serve-static-core/index" but cannot be named.
src\server.ts(6,7): error TS4023: Exported variable 'app' has or is using name 'Express' from external module "D:/Code/NodeJS/typescript-template/node_modules/@types/express-serve-static-core/index" but cannot be named.
TypeScript: 6 semantic errors
TypeScript: 3 declaration errors
TypeScript: 3 emit errors
TypeScript: emit failed
[18:20:36] Finished 'default' after 15 s

Your gulpfile:

gulp.task('default', () => {
	var src = gulp
		.src(['./src/**/*.ts'])
		.pipe($.typescript({
			declaration: true
		}));
		
	var test = gulp	
		.src(['./test/**/*.ts'])
		.pipe($.typescript({
			declaration: true
		}));
		
	return merge([
		src.pipe(gulp.dest('output/src')),
		test.pipe(gulp.dest('output/test'))
	])
});

Include your gulpfile, or only the related task (with ts.createProject).

tsconfig.json
Include your tsconfig, if related to this issue.

{
    "compilerOptions": {
        "target": "es6",
        "module": "commonjs",
        "sourceMap": true,
        "outDir": "output"
    },
    "include": [
        "src/**/*",
        "test/**/*"
    ]
}

Code

Include your TypeScript code, if necessary.

const router = express.Router();
@mirthlaj
Copy link
Author

I resolved some errors by running npm install --save-dev @types/es6-shim

Now I only have this ones:

src\routes\root.ts(3,7): error TS4023: Exported variable 'router' has or is using name 'Router' from external module "D:/Code/NodeJS/typescript-template/node_modules/@types/express-serve-static-core/index" but cannot be named.
src\routes\users.ts(3,7): error TS4023: Exported variable 'router' has or is using name 'Router' from external module "D:/Code/NodeJS/typescript-template/node_modules/@types/express-serve-static-core/index" but cannot be named.
src\server.ts(6,7): error TS4023: Exported variable 'app' has or is using name 'Express' from external module "D:/Code/NodeJS/typescript-template/node_modules/@types/express-serve-static-core/index" but cannot be named.

@mirthlaj
Copy link
Author

mirthlaj commented Feb 18, 2018

server.ts

import * as express from 'express';

import * as root from './routes/root';
import * as users from './routes/users';

const app = express();

app.use('/', root.router);
app.use('/', users.router);

app.listen(process.env.PORT, () => {
    console.log(`Listening on port ${process.env.PORT}`);
});

export default app;

root.ts

import * as express from 'express';

const router = express.Router();

router.get('/', (req, res, next) => {
    res.send({
        message: 'Hello World!'
    });
});

export {router};

This is my code in those files

@mirthlaj
Copy link
Author

I solved it by explicitly annotating the router and the express variables.

const router: express.Router = express.Router();
and
const app: express.Express = express();

@ivogabe
Copy link
Owner

ivogabe commented Feb 26, 2018

With your configuration, you are not using the tsconfig file. You need to use ts.createProject('./tsconfig.json'), see the readme for more information.

@trusktr
Copy link

trusktr commented Jul 28, 2019

I deleted (commented out) what I had in this comment.

ts(compilreOptions) is working one branch but not all (but tsc works on all branches). If I realize what is going on, I'll post back...

@trusktr
Copy link

trusktr commented Jul 29, 2019

Ok, I thought something was going wrong. Turns out I only get an issue like the one above during rebuilds in watch mode. So I made a new issue for that: #621

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants