node.js - "allowJS" errors in Typescript project on nodejs -
i'm getting error, , error related 'http' module (which working fine in straight js using require('http')
). here's errors:
index.ts(7,14): error ts2349: cannot invoke expression type lacks call signature. type 'typeof "http"' has no compatible call signatures.
index.ts(16,20): error ts6143: module './ofcmodules/db' resolved 'c:/users/stuff/root/ofcmodules/db/index.js', '--allowjs' not set.
db custom module. working fine in straight js using const db = require("./ofcmodules/db");
here's index.ts code:
"use strict" import * express 'express'; const app = express(); import * server "http"; const http = server(app); import * socketio "socket.io"; const io = socketio(http); import { db } "./ofcmodules/db";
i've tried import * db "./ofcmodules/db"
my directory structure hasn't changed 1 hour ago when importing/requiring stuff fine straight js. , have "allowjs" set true in tsconfig.json.
here's tsconfig.json:
{ "compileroptions": { "target": "es2017", "module": "commonjs", "sourcemap": true, "allowjs": true }, "files": [ "./node_modules/@types/node/index.d.ts" ] }
here's custom db module:
"use strict" const mysql = require("mysql"); class db { constructor(connection) { this.conn = connection; } //snip } export { db };
folder structure:
root -ofcmodules --db ---index.js -index.ts -package.json -tsconfig.json
the first thing notice you're calling http module (aliased 'server') function, should server.createserver
instead?
"use strict" // <= fyi, not necessary in typescript import * express 'express'; const app = express(); import * server "http"; const http = server(app); // <= line, should server.createserver? import * socketio "socket.io"; const io = socketio(http); import { db } "./ofcmodules/db";
i couldn't repro ofcmodules/db issue making .ofcmodules/db.ts
file, sorry, can post test project somewhere if you'd compare/contrast.
Comments
Post a Comment