question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Standard package.json key for .ts files

See original GitHub issue

A common TypeScript module structure looks like this:

src/index.ts
dist/index.js
dist/index.d.ts

and a package.json that looks like this:

  "main": "dist/index.js",
  "types": "dist/index.d.ts",

There’s a convention to use the package.json key jsnext:main to point to a variant of main that uses ES2015 module syntax. Can we develop a similar convention to point at .ts files, e.g. typescript:main?

Consider a TypeScript project that is sharded across many microlibraries (e.g. my-project-core, my-project-thing-plugin, my-project-other-thing-plugin). I’d like to be able to configure my bundler to import from src/*.ts files for any module whose name starts with my-project. Otherwise, it will be looking in dist/*.js and I’ll have to rebuild the plugins any time I make changes in them.

Of course, I could use jsnext:main for this purpose now, but any consumers who aren’t using TypeScript would get syntax errors for any files that contained TS-specific syntax like types. Similarly, I could make up my own package.json key and configure my bundler to look there first, but it behooves the community to have a convention here. That will allow bundlers like Webpack, Browserify, Rollup, and Pundle to look in the right place by default.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:11
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
blakeembreycommented, Jan 7, 2017

Side note (in case anyone else references the OP): the types field would usually point to dist/index.d.ts and not src.

0reactions
trusktrcommented, Jun 6, 2020

@mhegazy Sharing sources is the only way to get around the problems listed in #35822.

Read more comments on GitHub >

github_iconTop Results From Across the Web

package.json - npm Docs
This document is all you need to know about what's required in your package.json file. It must be actual JSON, not just a...
Read more >
Documentation - What is a tsconfig.json - TypeScript
The tsconfig.json file specifies the root files and the compiler options required to compile the project.
Read more >
What to put in package.json types field for typescript based libs
TypeScript Project References · VS Code navigation goes to the *.ts source file not to the *.d.ts file. · The package.json types value...
Read more >
The Basics of Package.json - NodeSource
This file is used as a manifest, storing information about applications, modules, packages, and more. Because understanding it is essential to ...
Read more >
Modules: Packages | Node.js v19.3.0 Documentation
Within a package, the package.json "type" field defines how Node.js should interpret .js files. If a package.json file does ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found