Yarn: Using link in package.json dependencies gives an error

Created on 14 Sep 2018  路  8Comments  路  Source: yarnpkg/yarn

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

As discussed with @arcanis in https://github.com/yarnpkg/rfcs/pull/101#issuecomment-421172456, I've come across an issue where using link: in package.json dependencies doesn't work for me.

I get a error Couldn't find a package.json file in /workspace/packages/project-a/src/one and error Couldn't find a package.json file in /workspace/packages/project-b/src/subdir1/subdir2/two.

If the current behavior is a bug, please provide the steps to reproduce.

  - package.json
  - packages
    - project-a
      - package.json
      - src
        - one
          - file1.js
        - subdir1
          - subdir2
            - two
              - file2.js

In workspace/packages/project-a/package.json I've linked them so that I can do require relative to one of a number of given root paths, which greatly simplifies writing require statements and makes refactoring code easier.

"dependencies": {
  "one": "link:./src/one",
  "two": "link:./src/subdir1/subdir2/two"
}

In workspace/package.json I have

{
  "private": true,
  "workspaces": [
    "packages/*"
  ]
}

What is the expected behavior?

I'd should be able to do require('one/file1.js') and require('two/file2.js') in the code.

Please mention your node.js, yarn and operating system version.

Node: 10.9.0
yarn: 1.9.4
OS: archlinux

triaged

All 8 comments

Thanks! 馃憤

@arcanis According to npm docs there should be file:./ instead of link:./. E.g.:

"dependencies": {
  "one": "file:./src/one",
  "two": "file:./src/subdir1/subdir2/two"
}

Could you please check that?

No. NPM decided to change the behavior of file: dependencies some time ago to become symlinks, but we decided against that. Instead, link: dependencies are the recommended way to create symlinks (workspaces are still a better choice if possible).

@arcanis Is there any docs about using "link:" instead of "file:" ? I looked for it in yarnpkg.com without success, I could make a PR for that unless it's already in some place I've missed 馃槄

Just wondering whether link: is working for anyone and it's not working in my case because of something specific to my project, or isn't working at all?

After updating react-scripts to v2.1.5, link it's not woking anymore. It's like peer dependecies weren't isntalled.

Same. It is not possible right now to install deps/build react with npm, only with yarn, because it has following:

    ...
    "eslint-plugin-react-internal": "link:./scripts/eslint-rules/",
    ...
Was this page helpful?
0 / 5 - 0 ratings