{"action":"created","issue":{"url":"https://api.github.com/repos/TypeStrong/ts-loader/issues/645","repository_url":"https://api.github.com/repos/TypeStrong/ts-loader","labels_url":"https://api.github.com/repos/TypeStrong/ts-loader/issues/645/labels{/name}","comments_url":"https://api.github.com/repos/TypeStrong/ts-loader/issues/645/comments","events_url":"https://api.github.com/repos/TypeStrong/ts-loader/issues/645/events","html_url":"https://github.com/TypeStrong/ts-loader/issues/645","id":260709625,"number":645,"title":"Problems transpiling `.js` files both local and within `node_modules`","user":{"login":"corsen2000","id":733656,"avatar_url":"https://avatars1.githubusercontent.com/u/733656?v=4","gravatar_id":"","url":"https://api.github.com/users/corsen2000","html_url":"https://github.com/corsen2000","followers_url":"https://api.github.com/users/corsen2000/followers","following_url":"https://api.github.com/users/corsen2000/following{/other_user}","gists_url":"https://api.github.com/users/corsen2000/gists{/gist_id}","starred_url":"https://api.github.com/users/corsen2000/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/corsen2000/subscriptions","organizations_url":"https://api.github.com/users/corsen2000/orgs","repos_url":"https://api.github.com/users/corsen2000/repos","events_url":"https://api.github.com/users/corsen2000/events{/privacy}","received_events_url":"https://api.github.com/users/corsen2000/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-09-26T17:39:54Z","updated_at":"2017-09-26T17:56:33Z","closed_at":null,"author_association":"NONE","body":"## Local JS Files\r\n\r\nI have a TypeScript project with `allowJs: true` and a basic Webpack configuration:\r\n\r\n```js\r\n      {\r\n        test: /\\.ts$/,\r\n        use: [{\r\n          loader: 'ts-loader',\r\n          options: {\r\n            configFileName: 'tsconfig.json'\r\n          }\r\n        }],\r\n        exclude: /node_modules/\r\n      }\r\n```\r\n\r\nWhen I build the project using this configuration only the `.ts` files have their ES6 transpiled down to ES5. The `.js` files are not processed.\r\n\r\nMy first though to fix this was to update the test expression to be `test: /\\.(ts|js)$/,`, but this single change results in an error `ERROR in error TS18002: The 'files' list in config file 'tsconfig.json' is empty.`.\r\n\r\nI can resolve this by adding `include: [projectSrc],` to the webpack configuration, but I don't understand why I have to do this.\r\n\r\n## Node Modules\r\n\r\nI was not able to figure how to extend what I did above to also transpile `.js` files within `node_modules`. I install some dependencies that only ship ES6 code and I need that to be transpiled. I attempted to solve this by adding a separate `ts-loader` for `.js` files:\r\n\r\n```js\r\n      {\r\n        test: /\\.js$/,\r\n        include: [projectSrc, projectModules],\r\n        use: [{\r\n          loader: 'ts-loader',\r\n          options: {\r\n            configFileName: 'tsconfig.json',\r\n            transpileOnly: true\r\n          }\r\n        }]\r\n      }\r\n```\r\n\r\nIn this case I had to add `include: [projectSrc, projectModules]` to work around the empty files error from the first case. It continues to successfully allow me to import `.js` files from the local project, but files in `node_modules` do not work. I get errors that look like `Module build failed: Error: Could not find file: 'SOME_NODE_MODULE_PATH'.`\r\n\r\nIt seems that my `.js` loader causes the `.ts` loader to no longer be able to find the files.\r\n\r\n## Using Babel\r\n\r\nAlthough not complete adding Babel to handle JS files seems to be off to a much better start:\r\n\r\n```js\r\n      {\r\n        test: /\\.js$/,\r\n        use: [{\r\n          loader: 'babel-loader',\r\n          options: {\r\n            presets: ['es2015']\r\n          }\r\n        }]\r\n      },\r\n```\r\n\r\nThis more or less works out of the box.\r\n\r\n## Conclusion \r\n\r\nI am considering just using Babel since it is working out of the box, but I had originally hoped to not have to add another tool since TypeScript has this transpilation logic built in. Additionally, I prefer TypeScript's `tslib` approach for helpers.\r\n\r\nI can put together a reproducer repository if needed, but was first curious if others have tried this and perhaps had an example configuration that worked.\r\n\r\nThank you."},"comment":{"url":"https://api.github.com/repos/TypeStrong/ts-loader/issues/comments/332282130","html_url":"https://github.com/TypeStrong/ts-loader/issues/645#issuecomment-332282130","issue_url":"https://api.github.com/repos/TypeStrong/ts-loader/issues/645","id":332282130,"user":{"login":"johnnyreilly","id":1010525,"avatar_url":"https://avatars0.githubusercontent.com/u/1010525?v=4","gravatar_id":"","url":"https://api.github.com/users/johnnyreilly","html_url":"https://github.com/johnnyreilly","followers_url":"https://api.github.com/users/johnnyreilly/followers","following_url":"https://api.github.com/users/johnnyreilly/following{/other_user}","gists_url":"https://api.github.com/users/johnnyreilly/gists{/gist_id}","starred_url":"https://api.github.com/users/johnnyreilly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johnnyreilly/subscriptions","organizations_url":"https://api.github.com/users/johnnyreilly/orgs","repos_url":"https://api.github.com/users/johnnyreilly/repos","events_url":"https://api.github.com/users/johnnyreilly/events{/privacy}","received_events_url":"https://api.github.com/users/johnnyreilly/received_events","type":"User","site_admin":false},"created_at":"2017-09-26T17:56:33Z","updated_at":"2017-09-26T17:56:33Z","author_association":"OWNER","body":"See https://github.com/TypeStrong/ts-loader/tree/master/examples/vanilla-jsts"}}
{"actor":{"display_login":"johnnyreilly"}}