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.

Secondary entry point bug: `src/` path gets part of package import path

See original GitHub issue

Type of Issue

[x] Bug Report
[ ] Feature Request

Description

When placing the main entry point in src/ and every subentry point in a new folder inside src/ you will get the primary point correctly at @my/package-name but every secondary entry point is only accessible by the path @my/package-name/src/*.

This is a remaining error after fixing the base url stuff in this PR https://github.com/dherges/ng-packagr/pull/862

Relates to: https://github.com/dherges/ng-packagr/issues/854

How To Reproduce

I created a new example in the ng-packagr project. See my branch https://github.com/georgiee/ng-packagr/tree/src-entry-point-bug.

  1. Launch example nested-src.
  2. It works. But only because it’s fixed by providing this import
import { STATIC_FOO_VALUE, FooClass } from '@sample/nested-src/src/foo';

instead of

import { STATIC_FOO_VALUE, FooClass } from '@sample/nested-src/foo';

Expected Behaviour

This path should work:

import { STATIC_FOO_VALUE, FooClass } from '@sample/nested-src/foo';

Version Information

$: ng -v
@angular-devkit/architect    0.6.3 (cli-only)
@angular-devkit/core         0.6.0
@angular-devkit/schematics   0.6.3 (cli-only)
@angular/cdk                 6.0.1
@angular/router              6.0.1
@ngtools/json-schema         1.1.0
@schematics/angular          0.6.3 (cli-only)
@schematics/update           0.6.3 (cli-only)
rxjs                         6.1.0
typescript                   2.7.2

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:8
  • Comments:30 (14 by maintainers)

github_iconTop GitHub Comments

6reactions
stweediecommented, Nov 5, 2018

Is there any intention on clarifying why placing package.json under the src folder works here? First, it is very commonplace and standard for the package.json to be at the root level of the package it is describing. Second, it’s not intuitive that

root (abc/def)
|--package.json
|--ng-package.json
|--src
  |--main
    |--public_api.ts
    |--...
  |--secondary
    |--package.json
    |--public_api.ts
    |--...

produces the packages:

abc/def
abc/def/src/secondary

while

root (abc/def
|--src
  |--package.json
  |--ng-package.json
  |--main
    |--public_api.ts
    |--...
  |--secondary
    |--package.json
    |--public_api.ts
    |--...

produces the packages:

abc/def
abc/def/secondary

Issues with pathing and dependencies notwithstanding, the location of my source code does not change. Why does the location of the package.json file itself dictate package destinations?

My exact use case doesn’t need a main module so I would rather have a package.json at the root that has a name of the common namespace (abc/def, in my example) and is completely independent from the packaged code itself and ng/package.json files in each of the feature modules that dictate how they would be packaged.

5reactions
william-lohancommented, May 25, 2018

This also effects when adding secondary entry point to lib generated from ng g library

Read more comments on GitHub >

github_iconTop Results From Across the Web

Service is not under 'rootDir' in Angular secondary entry point
I understand that the compilation of secondary entry points is separate and "treated as a separate project", hence the error.
Read more >
importlib — The implementation of import — Python 3.11.1 ...
The path argument should be the “path” to where the source code originated from, which can be an abstract concept (e.g. location in...
Read more >
How to improve your Angular library | Developapa
You can NOT use relative imports between difference entry points. You need to import from the build package like you would from a...
Read more >
Building an Angular Library with multiple entry points | Articles
A npm package can have additional entry points, called secondary entry ... It specifies the path of the build output and the entry...
Read more >
Documentation - Module Resolution - TypeScript
Use non-relative paths when importing any of your external dependencies. ... In our example, if Node.js found the file /root/src/moduleB/package.json ...
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