Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link: relative main field #96

Open
anilanar opened this issue Feb 2, 2017 · 6 comments
Open

Link: relative main field #96

anilanar opened this issue Feb 2, 2017 · 6 comments

Comments

@anilanar
Copy link
Contributor

anilanar commented Feb 2, 2017

Code to reproduce the issue:

northbrook link

Expected behavior:

Generated package.json files should use relative path for main field.

Actual behavior:

They use absolute path.


According to https://docs.npmjs.com/files/package.json#main, mainis a relative path. Webpack assumes the same, thus I cannot build linked packages with webpack.

Edit: According to official docs from node, module resolution algorithm is as follows:

LOAD_AS_DIRECTORY(X)
 1. If X/package.json is a file,
   a. Parse X/package.json, and look for "main" field.
   b. let M = X + (json main field)
   c. LOAD_AS_FILE(M)

I guess X + (json main field) implies that it cannot be an absolute path.

@anilanar
Copy link
Contributor Author

anilanar commented Feb 2, 2017

Actually, relative paths with ../pkgName/index.js doesn't work either, sad.

Your approach of linking is a very good idea. It works with node and jest. I assume it works with mocha, typescript etc, and there's a workaround for webpack using moduleDirectories.

I wonder if we can ask node to allow relative paths outside module root (or absolute paths) and ask webpack to implement it.

@TylorS
Copy link
Member

TylorS commented Feb 2, 2017

Hello @anilanar, thank you for the issue. This is very good information to have, I was unaware of this problem with webpack. I've not used webpack with northbrook yet.

I'll try to look into how to solve this issue. Any chance you have a repo I could pull to reproduce this issue?

@anilanar
Copy link
Contributor Author

anilanar commented Feb 2, 2017

I will setup a basic repo, the one I'm working on is not open source (yet).

@anilanar
Copy link
Contributor Author

anilanar commented Feb 2, 2017

@TylorS
Copy link
Member

TylorS commented Feb 6, 2017

Great, thanks. I'll take a look at this soon.

@TylorS
Copy link
Member

TylorS commented Feb 8, 2017

image

I was able to get this working by adjusting the main field to a relative path. I'll try to get a fix for it in soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants