Skip to content

Instantly share code, notes, and snippets.

@cspotcode
Last active February 28, 2017 08:18
Show Gist options
  • Save cspotcode/217f364daed15cb7aa06568313b0c933 to your computer and use it in GitHub Desktop.
Save cspotcode/217f364daed15cb7aa06568313b0c933 to your computer and use it in GitHub Desktop.
ts-loader .jsx bug reproduction

To reproduce:

$ npm install
$ npm run tsc
# tsc emits all code to tsc-out as expected
$ npm run webpack
# Errors indicate that it can't find either .jsx files but it can find the .js files

Webpack output:

ts-loader: Using typescript@2.1.4 and /Users/cspotcode/Desktop/ts-loader-jsx-bug-repro/tsconfig.json
Hash: c8f7c10cb7c365894513
Version: webpack 1.14.0
Time: 766ms
              Asset     Size  Chunks             Chunk Names
webpack-out/main.js  2.09 kB       0  [emitted]  main
    + 5 hidden modules

ERROR in ./jsxFile1.jsx
Module build failed: Error: Could not find file: '/Users/cspotcode/Desktop/ts-loader-jsx-bug-repro/jsxFile1.jsx'.
    at getValidSourceFile (/Users/cspotcode/Desktop/ts-loader-jsx-bug-repro/node_modules/typescript/lib/typescript.js:78776:23)
    at Object.getEmitOutput (/Users/cspotcode/Desktop/ts-loader-jsx-bug-repro/node_modules/typescript/lib/typescript.js:79141:30)
    at getEmit (/Users/cspotcode/Desktop/ts-loader-jsx-bug-repro/node_modules/ts-loader/dist/index.js:84:43)
    at Object.loader (/Users/cspotcode/Desktop/ts-loader-jsx-bug-repro/node_modules/ts-loader/dist/index.js:24:11)
 @ ./entry.ts 2:0-21

ERROR in ./jsxFile2.jsx
Module build failed: Error: Could not find file: '/Users/cspotcode/Desktop/ts-loader-jsx-bug-repro/jsxFile2.jsx'.
    at getValidSourceFile (/Users/cspotcode/Desktop/ts-loader-jsx-bug-repro/node_modules/typescript/lib/typescript.js:78776:23)
    at Object.getEmitOutput (/Users/cspotcode/Desktop/ts-loader-jsx-bug-repro/node_modules/typescript/lib/typescript.js:79141:30)
    at getEmit (/Users/cspotcode/Desktop/ts-loader-jsx-bug-repro/node_modules/ts-loader/dist/index.js:84:43)
    at Object.loader (/Users/cspotcode/Desktop/ts-loader-jsx-bug-repro/node_modules/ts-loader/dist/index.js:24:11)
 @ ./entry.ts 3:0-25
import './jsxFile1'; // fails in webpack
import './jsxFile2.jsx'; // fails in webpack
import './jsFile1'; // succeeds in webpack
import './jsFile2.js'; // succeeds in webpack
export const file = 'jsFile1';
export const file = 'jsFile2';
export const file = 'jsxFile1';
export const file = 'jsxFile2';
{
"name": "ts-loader-jsx-bug-repro",
"version": "1.0.0",
"scripts": {
"tsc": "tsc -p .",
"webpack": "webpack"
},
"dependencies": {
"ts-loader": "^1.3.2",
"typescript": "^2.1.4",
"webpack": "^1.14.0"
}
}
{
"compilerOptions": {
"allowJs": true,
"outDir": "tsc-out"
},
"exclude": ["node_modules", "webpack-out", "tsc-out", "webpack.config.js"]
}
module.exports = {
entry: './entry',
output: {
filename: 'webpack-out/[name].js'
},
resolve: {
extensions: ['.ts', '.jsx', '.js', '']
},
module: {
loaders: [
{
loader: 'ts',
// `entryFileIsJs` should not be necessary because the *entry* file is .ts
// I have confirmed that this is not necessary to import .js files,
// but it apparently is necessary to import .jsx files.
/*query: {
entryFileIsJs: true
}*/
}
]
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment