Typescript emitted no output
See original GitHub issueExpected Behaviour
Get compiled js from ts
Actual Behaviour
Getting the following error:
Module build failed: Error: Typescript emitted no output for C:\xampp\htdocs\node-api\src\js\server.ts. at successLoader (C:\xampp\htdocs\node-api\node_modules\ts-loader\dist\index.js:39:15) at Object.loader (C:\xampp\htdocs\node-api\node_modules\ts-loader\dist\index.js:21:12) at eval (webpack:///./src/js/server.ts?:1:7) at Object…/src/js/server.ts (C:\xampp\htdocs\node-api\dist\js\server.js:81:1) at webpack_require (C:\xampp\htdocs\node-api\dist\js\server.js:20:30) at C:\xampp\htdocs\node-api\dist\js\server.js:69:18 at Object.<anonymous> (C:\xampp\htdocs\node-api\dist\js\server.js:72:10) at Module._compile (module.js:652:30) at Object.Module._extensions…js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3)
Steps to Reproduce the Problem
Use npm run dev
in the repository below. Or use the following config files:
Webpack:
const path = require( 'path' ),
CleanWebpackPlugin = require( 'clean-webpack-plugin' );
module.exports = env => {
return {
mode: env.dev ? 'development' : 'production',
entry: {
'server': './src/js/server.ts'
},
output: {
path: __dirname,
filename: './dist/js/[name].js',
},
externals: '/node_modules',
module: {
rules: [
{
test: /\.js$/,
exclude: ['/node_modules/', '/src/scss/'],
use: [
'babel-loader'
]
},
{
test: /\.ts(x?)$/,
exclude: ['/node_modules/', '/src/scss/'],
use: [
'babel-loader',
'ts-loader',
]
},
{
test: /\.json$/,
loader: 'json-loader'
},
]
},
resolve: {
extensions: ['.js', '.ts', '.tsx'],
alias: {
'@': path.resolve(__dirname, './src/js')
}
},
plugins: [
new CleanWebpackPlugin(['./dist/js', './dist/css']),
]
}
};
Typescript:
{
"compilerOptions": {
"removeComments": true,
"preserveConstEnums": true,
"allowJs": true,
"outDir": "./dist/js",
"target": "es5",
"moduleResolution": "node",
"module": "es2015",
"lib": [
"es2015",
"es2016"
]
},
"exclude": [
"./node_modules"
]
}
Babel:
{
"presets": [
[
"env", {
"targets": {
"node": "current"
}
}
],
"stage-2",
"es2015"
],
"plugins": ["dynamic-import-node"]
}
Location of a Minimal Repository that Demonstrates the Issue.
Issue Analytics
- State:
- Created 5 years ago
- Comments:15 (2 by maintainers)
I ran into this error when I had
"noEmit": true,
in my tsconfig.jsonFor lost googlers:
noEmit: true
mistake can happen when easily when you try to reuse a Next.js TypeScript config. Next do not need to actually emit the JS file and uses the tsconfig internally. But if you try to reuse your base config for external tooling, eg Storybook, building a server and so on, don’t forget to addnoEmit: false
to the extended config.