My current folder structure for typescript:
ts_dev
--client
*components.tsx
*tsconfig.json
--server
*server.ts
*tsconfig.json
--share
*utility.ts
The Node.js server needs to use commonjs modules, and es2015 for the client side components. I place the share folder used by both client and server under the server directory because it needs commonJS for Node.js.
tsconfig.json in server:
{
"compilerOptions": {
"module": "commonJS",
"target": "es2015",
"moduleResolution": "node",
"outDir": "../../src",
"lib": ["es6", "dom"],
"types": ["reflect-metadata","system"],
"jsx": "react"
},
"exclude": [
"node_modules",
]
}
tsconfig.json in client:
{
"compilerOptions": {
"module": "es2015",
"target": "es2015",
"moduleResolution": "node",
"outDir": "../../src",
"lib": ["es6", "dom"],
"types": ["reflect-metadata","system"],
"jsx": "react"
},
"exclude": [
"node_modules",
]
}
However I find that the scripts in share are always complied in es6 (Use export,import etc) instead of commonJS, which breaks my server. I suspect it's caused by the tsconfig in the client. What can I do to fix this issue?