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.

Accessing sources from npm package

See original GitHub issue

Hello!

I have a project in which I use typedi through npm. The npm-package includes source-map files for all .js files. However, those source maps reference original files like this: ../../src/Container.ts, so this path leads outside of node_modules directory and points to non-existent source files.

I’m using source-map-support module to make stack traces more readable, but the source maps of typedi make reported paths weird. It tries to resolve them to files in my project. This complicates debugging.

Actually, I would love those stack traces to be resolved back to original TypeScript files, but sadly the npm-package doesn’t contain source files at all. If source files were present it would allow to much easier trace and resolve errors in projects and even to use debugger to dive into internals of typedi when used with the real project (this really helps with integration).

So, I think there could be two courses of action:

1). Add source .ts files to the npm-package.

2). Remove source maps from npm package because they point to inexistent files.

Does it makes sense?

Thank you.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
slavafomincommented, May 3, 2017

Why don’t you want to treat TypeScript files as a first class citizens? We are developing a TypeScript modules are we not? The generated .js files should be actually treated like secondary ones and only for the sake of users who don’t want to compile them themselves.

Shipping Typescript files instead of plain js files would make this project consumable by Typescript projects only…

I totally agree with you, but I’ve never proposed to ship them instead of .js, I’m proposing to ship them as a main code and ship generated .js additionally to .ts for better compatibility with native (vanilla) JavaScript projects. So the package = TS [+ JS].

It’s really nice to have source files inside node_modules, because when error happens, or when you debugging things interactively with IDE you can just click on a stack trace and navigate around the call stack. This is invaluable when integrating project with third-party dependencies. And I truly believe that this must be an integral part of great developer experience. For example reflect-metadata module contains source files and it makes working with this module very convenient.

It’s very helpful to see method or class implementation when you navigate around classes, but instead you have to see blunt typings. So in order to study internals of the typedi or typeorm I have to open them in a separate window as a separate IDE project and to copy-paste class names or paths to files. This makes no sense at all.

no, we cant ship ts files with package, it should not be done at all

Could you elaborate on this please? What are the actual drawbacks?

If source maps point to wrong location then they simply need to be fixed. Try to debug and figure out why paths aren’t valid.

How do you propose to fix them? The source maps only contain a reference to the original source file, which allows to resolve the actual place in it. If there is no source files in the package, then there is no sense for keeping the source maps, because it breaks the IDE (source-maps just point nowhere). It would be even better without source maps at all — at least you will be able to see the error in generated .js files instead of broken references.

0reactions
github-actions[bot]commented, Jul 31, 2020

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using npm packages in your projects
If you are creating a Node.js module, you can use a package in your module by passing it as an argument to the...
Read more >
HOWTO: Inspect, Download and Extract NPM Packages
This article explains how to inspect, download, and extract NPM packages step-by-step.
Read more >
Accessing NPM public vs private package source code in ...
So I'm wondering what the difference is between public and private npm packages since one can view the source code via node_modules folder ......
Read more >
Using Open-Source npm packages - Beginner JavaScript
When you install node modules, you will see that a folder called node-modules is generated and inside of that folder there is always...
Read more >
Using npm Packages - Meteor Guide
Using npm packages. To use an npm package from a file in your application you import the name of the package: import moment...
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