yarnpkg/yarn

yarn doesn't run prepublish script and include EVERTHING into the package when adding a local dependency

bchenSyd opened this issue Β· 25 comments

Hi there,
I'm building my own package and I have an example folder in my project as a demo. My project structure is like this:

   -root
     - node_modules
     - example
           -node_modeules
               - my-library
        -index.html
        -index.js
        -package.json 
      - src
          -library.js
      readme.md
      package.json 

Inside example folder, the package.json file has

"dependencies":{
    "my-library":"file:../"
}

and when I run npm install , I can see my library prepublish script is invoked and that my project is built and finally added to example\node_modules\ . This is exactly what I expected.

However, When I tried the same thing using yarn install, it didn't work, at all. Note I have cleared yearn cache, so it's not a cache issue. The problem is like, when running yarn install, it seems yarn doesn't honour my package.json defined in root folder. my /root/package.json has

    "name":"my-library"
    "version":"1.0.0"
    "main":"lib/result.js"
    "files":"["lib"]"
    "script":{
        "prepublish":"create a lib folder and put the compiled result into it"
   }

Basically, yarn ignored files section, which tells npm/yarn to only include lib folder in the result package, and built everything into the result package. I can also confirm that yarn is not calling prepublish script as npm does in this case

note: if I publish my library to npm registry, and then do yarn install my-library everything works as expected.

any ideas??

Also, I did another test

-root
    - example
        -package.json
    -lib
      -lib.js
    -src
      -test.js
    package.json

in root\package.json, try

    "name":"parent",
    "main":"lib\lib.js",
    "files":["lib"]

then in root\example\package.json, have

dependencies:{
   "parent":"file:../"
}

to test the difference

  1. cd root\example\; npm install
  2. cd root\example\; yarn install

compare the result in root\example\node_modues\parent\

the npm one only has lib folder, but the yarn one has everything (both lib and src )

why is such a case?

What version of yarn are you running?

$ yarn info
yarn info v0.16.0

I'm facing the same issue, do you have any work around for this?

I'm having the same issue for now I'm going to have to switch to using regular old npm so I can develop my SDK in tandem with my application 😒

I have the same problem with yarn 0.21.3

it's been like this since first public release but, this behavior is entirely different from npm.

Hey any work on this ? I'd like to easily be able to fork github projects, contribute, and keep using my forks until the PR pass and I can revert to using the main repo.
Since yarn isn't doing the prepublish step it won't create the dist/ folder and I can't run my components

I know some prepublish steps are complicated but for most small projects I assume it should be fine to always have yarn try it ?

I did some initial exploration on the bug, I see that lifehook scripts are executed but are not treated as commands

This also seems to be the case for forked projects added via Github address.

Facing the same issue. May I know is there any update?

Subscribing so I can know when this is fixed.

Reported almost a year ago, and no updates?

same here. i forked a github repo, made my changes and when i try to install using my github URL, it doesnt run the prepublish step and doesn’t build the module. i changed the main in package.json in my fork to work around this, but would be nice if yarn handled this itself.

I'm having the same issue as @suchitagarwal. When I run yarn install, I can see that the prepare script of my forked GitHub repo is being run, but the generated files are not being included in the node_modules folder. This works fine on my macOS systems, but fails on all of my Windows systems.

Ugh. I am having this issue too. What has everyone been using as a workaround?

@benmcmaster, because I had forked the repo, I just changed the main in package.json to do what i needed it to do.

@suchitagarwal interesting! Can you share your example?

It's a private repo, so I can't share that directly. But actually what I did was slightly different. I forked the repo, ran the prepublish, checked in the output to my fork, and then used that instead.

Here's the first example I've found which isn't a local package, but rather a Github branch. Post-installs don't run, so the package is not usable without additional work.

yarn add https://github.com/tomkp/react-split-pane/tarball/2516ee2de023cc51e9a18e471f42b608be19c8ad

Expected results:

  • React-split-pane installs
  • node_modules\react-split-pane\lib\ exists and contains built project files.

Actual results:

  • React-split-pane installs
  • node_modules\react-split-pane\lib\ DOES NOT exist.

This issue has been open for well over a year now. Is there any plan to address this? We've not seen a single response from a maintainer on this issue, and it is seriously detrimental to need to spend so much extra time to get packages working because yarn simply neglects to run this command in certain circumstances.

rtsao commented

@slapbox I did some initial investigation into the bug in #5235 which discusses the root cause and how it might be fixed. I think making a patch for this would be a fairly reasonable undertaking, hopefully someone will be able to tackle this.

Agreed this is a high priority bug!

I think this issue is why publishing typescript modules is not working.