Closed abossard closed 6 years ago
What is your tsconfig? You probably should exclude **/node_modules/*
from the compilation.
I already excluded the node_modules:
{
"compilerOptions": {
"outDir": "build",
"module": "commonjs",
"target": "es5",
"lib": [
"ES2017",
"es6",
"dom"
],
"sourceMap": true,
"allowJs": true,
"jsx": "react",
"moduleResolution": "node",
"baseUrl": "./",
"paths": {
"*": ["src/types/*", "*"]
},
"rootDir": "src",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": false
},
"exclude": [
"node_modules",
"build"
]
}
if you add "*/node_modules/" instead of "node_modules" the same result? What is the code in server.ts? (to reproduce)
Under Mac OS: same result. Works with Windows! No joke. This is my server.ts
import * as dotenv from "dotenv";
import * as Koa from "koa";
import * as bodyParser from "koa-bodyparser";
import * as mount from "koa-mount";
import * as passport from "koa-passport";
import * as route from "koa-route";
import * as session from "koa-session";
import * as serve from "koa-static";
import * as AD from "passport-azure-ad";
import {handleRender} from "./handleRender";
dotenv.config();
const {
PORT = 3001,
HOST = "0.0.0.0",
REDIS_API_URL = "",
AD_CALLBACK_URL = "",
AD_CLIENT_ID = "",
AD_TENANT = "",
AD_RESOURCE = "",
SESSION_SECRET = "",
AD_CLIENT_SECRET = "",
} = process.env;
const app = new Koa();
const fetchUser = async (criterion: object) => {
return Object.assign({ id: 1, username: "test" }, criterion);
};
passport.serializeUser((user, done) => {
done(null, JSON.stringify(user));
});
passport.deserializeUser(async (id, done) => {
try {
const user = await fetchUser(JSON.parse(id));
done(null, user);
} catch (err) {
done(err, null);
}
});
passport.use(new AD.OIDCStrategy({
allowHttpForRedirectUrl: true,
clientID: AD_CLIENT_ID,
clientSecret: AD_CLIENT_SECRET,
identityMetadata: "https://login.microsoftonline.com/common/.well-known/openid-configuration",
redirectUrl: AD_CALLBACK_URL,
responseMode: "query",
responseType: "id_token code",
}, (iss, sub, profile, accessToken, refreshToken, done) => {
fetchUser({ accessToken, name: profile.displayName, upn: profile.upn})
.then((user) => {
done(null, user);
} ).catch(done);
}));
app.proxy = true;
app.keys = [SESSION_SECRET];
// sessions
app.use(session({}, app));
// body parser
app.use(bodyParser());
app.use(passport.initialize());
app.use(passport.session());
app.use(mount("/static", serve("./build/htdocs")));
app.use(route.get("/auth/ad", passport.authenticate("azuread-openidconnect", {
prompt: "login",
resourceURL: AD_RESOURCE,
tenantIdOrName: AD_TENANT,
})));
app.use(route.get("/auth/ad/callback", passport.authenticate("azuread-openidconnect", {
failureRedirect: "/",
resourceURL: AD_RESOURCE,
successRedirect: "/nice",
tenantIdOrName: AD_TENANT,
})));
app.use(route.get("/nice", (context) => {
if (context.isAuthenticated()) {
context.body = "Logged in: " + JSON.stringify(context.state.user);
} else {
context.body = "Really not logged in";
}
context.body += JSON.stringify(context.session);
}));
app.use(route.get("/auth/logout", (context) => {
context.logout();
context.redirect("/");
}));
app.use(handleRender());
app.listen(Number(PORT), HOST, () => {
process.stdout.write(`Running on http://${HOST}:${PORT} \n`);
process.stdout.write(`Redis at ${REDIS_API_URL}\n`);
});
process.on("SIGINT", () => {
process.stdout.write("Shutdown.");
process.exit(0);
});
And as I mentioned: works with Windows and Node.js 8.7.0.
Maybe it's a Mac specific issue?
Suggestions, either:
1) Change cache-dir (--cache-directory
option) maybe to cwd, and check if compiled file exists.
2) Set allowJS: false
in tsconfig and try without it.
Hey @whitecolor, thank you so much!
allowJs: false
did the trick.
So for future reference: on Mac OS it required allowJs: false
in the tsconfig.
on Mac OS it required allowJs: false in the tsconfig.
I actually will fix it here too, files in /node_modules/ should be ignore by default. Thanks for reporting about the problem.
should be fixed now
Hi, I habe a Koa based Typescript application and when I try to run it, I get this error: