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.

Postinstall patch script unreliable

See original GitHub issue

General Information

  • Usage
  • Development
  • Documentation
  • Feature Request

Specific generator

  • Addons
  • HandlebarsJS

What Version you are running?

  • NodeJS: v.10.18.0
  • NPM: 6.13.4
    • (Yarn v1.19.2)
  • @pnp/spfx: v1.10.2

Describe your problem

The postinstall patch script is unreliable, since it relies on all the dependency modules being installed inside the package’s own install directory. Installing with NPM globally will yield this result, however installing locally with either NPM or Yarn, or installing globally with Yarn, will not.

Instead, the modules are installed at the root of node_modules meaning this path (and various other paths) are no longer correct. This causes the package to fail installation.

error C:\Users\jake.stanger\AppData\Local\Yarn\Data\global\node_modules\@pnp\generator-spfx: Command failed.
Exit code: 1
Command: node lib/patch.js
Arguments:
Directory: C:\Users\jake.stanger\AppData\Local\Yarn\Data\global\node_modules\@pnp\generator-spfx
Output:
fs.js:114
    throw err;
    ^

Error: ENOENT: no such file or directory, mkdir 'C:\Users\jake.stanger\AppData\Local\Yarn\Data\global\node_modules\@pnp\generator-spfx\node_modules\@microsoft\generator-sharepoint\lib\generators\applicationCustomizer\templates\react'       at Object.mkdirSync (fs.js:757:3)
    at Object.<anonymous> (C:\Users\jake.stanger\AppData\Local\Yarn\Data\global\node_modules\@pnp\generator-spfx\lib\patch.js:123:8)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)

The script could use require.resolve to get the path for the the module. The downside to this is that the generator will be modifying an install of the base generator that may not be associated with this generator. The upside is it should always work.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
JakeStangercommented, Jan 20, 2020

Awesome, thanks!

1reaction
JakeStangercommented, Jan 2, 2020

Okay just installed the alpha version as a dep and it worked fine. Awesome!

We use a generator internally that first runs this generator and then adds some company specific patches such as extra configs etc.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Running npm `postinstall` script after the original ...
Considering tampering directly with the package.json is bad practice, because Devs will no longer be in control of the packages they have ...
Read more >
Untitled
The postinstall script creates the backout package using the information ... In the example, undoing the patch is permitted by constructing a stream...
Read more >
12 strange things that can happen after installing an NPM ...
preinstall , install and postinstall scripts are automatically executed by npm when you install a package, preuninstall and postuninstall — when ...
Read more >
How to Patch a Broken Npm Library - Beyond Java
Most of the time, you can fix the problem yourself, at least for a while. ... Add this post-install script to the package.json...
Read more >
Patching node packages - mykter.com
npm will run the postinstall script if it's specified in package.json. You could use this to apply a patch to the installed module....
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