{"id":17749525,"url":"https://github.com/oresoftware/ts_bug_repro","last_synced_at":"2025-04-01T08:11:31.716Z","repository":{"id":95713230,"uuid":"135638279","full_name":"ORESoftware/ts_bug_repro","owner":"ORESoftware","description":"Reproducing a tsc compilation bug/feature for the TypeScript people.","archived":false,"fork":false,"pushed_at":"2018-05-31T22:12:17.000Z","size":11,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-03-02T00:26:09.211Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ORESoftware.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-31T21:44:58.000Z","updated_at":"2018-05-31T22:20:10.000Z","dependencies_parsed_at":"2023-05-21T17:45:31.900Z","dependency_job_id":null,"html_url":"https://github.com/ORESoftware/ts_bug_repro","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ORESoftware%2Fts_bug_repro","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ORESoftware%2Fts_bug_repro/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ORESoftware%2Fts_bug_repro/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ORESoftware%2Fts_bug_repro/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ORESoftware","download_url":"https://codeload.github.com/ORESoftware/ts_bug_repro/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246604611,"owners_count":20804100,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-26T11:23:36.609Z","updated_at":"2025-04-01T08:11:31.685Z","avatar_url":"https://github.com/ORESoftware.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\n## Project showing a potential bug in tsc transpilation\n\nIn package_a, we have a tsconfig.json file with these typeRoots:\n\n```\n    \"typeRoots\": [\n      \"./node_modules/@types\",\n      \"./node_modules/@oresoftware/package_b/dts\"\n    ]\n\n```\n\n\npackage_a depends on package_b\n(they are published to @oresoftware/package_a and @oresoftware/package_b, but you don't need to use NPM to reproduce the problem)\n\n\n### Here is the problem\n\nhere is the source structure for package_a:\n\n```\n/src\n  a.ts\n```\n\nand a.ts looks like:\n\n```\nimport * as x from 'lodash';\n\nexport {Foo} from '@oresoftware/package_b/dts/b'  \n\nconsole.log(x);\n```\n\n\nif you go into package_a, and run `tsc`, you will get this dist structure:\n\n```\ndist/\n  a.d.ts\n  a.js\n```\n\n\nand a.js looks like this:\n\n\n```js\n\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst x = require(\"lodash\");\nvar b_1 = require(\"@oresoftware/package_b/dts/b\");\nexports.Foo = b_1.Foo;\nconsole.log(x);\n```\n\n\nThe *problem* is it's trying to load:\n\n```\nvar b_1 = require(\"@oresoftware/package_b/dts/b\");\n```\n\nat runtime, even though this is a `.d.ts` file!\n\nMy guess is that `tsc` just guesses that it's loadable,\nbecause it could not find the file at compile time.\n\n\nHow to fix the problem!\n\nIf you cd into package_a and run `npm install`, and then run `tsc`, the problem goes away,\nwe now have this `dist/a.js` file:\n\n```js\n\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst x = require(\"lodash\");\nconsole.log(x);\n```\n\nso, idk if this is a bug or not.\n\n\u003cbr\u003e\nIn summary, if the .d.ts files are present `tsc` knows what they are obviously.\nIf the .d.ts files are missing, it assumes that they are .js files and generates\ncode to load those files at runtime which then breaks at runtime because\nthe files are not .js files.\n\u003c/b\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foresoftware%2Fts_bug_repro","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foresoftware%2Fts_bug_repro","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foresoftware%2Fts_bug_repro/lists"}