sp-dev-docs icon indicating copy to clipboard operation
sp-dev-docs copied to clipboard

Custom SPFx Library from npm package child_process stuck on gulp serve configure-webpack

Open henkterharmsel opened this issue 8 years ago • 3 comments

Category

  • [ ] Question
  • [ ] Typo
  • [ x] Bug
  • [ ] Additional article idea

Expected or Desired Behavior

We have create our own SPFx library component package to use in multiple webpart we create. I have published this package as a npm package to our Azure DevOps Artifacts and imported the NPM package in a SPFx webpart. While running gulp serve I was hoping to see the package resolved correctly.

Observed Behavior

While running gulp serve the serving get's stuck on the configure-webpack subtask. After a lot of debugging I have found that the problem is in the fact that our package does have a dev dependency reference to the "child_process" npm package. In the sp-build-core-tasks npm package there is a file named cumulativeManifestProcessor.js (in the lib folder) which is trying to resolve npm packages and making sure a package is not added twice. (not exactly sure what it's doing)

The resolving part for each package happens on the line with "Resolve_1.resolvePackage(packageName, packagePath)", which leads to the lib/utilities/Resolve.js in the same sp-build-core-tasks npm package. This finally lead to the sync function from the browserify resolve npm package. In here it is trying to resolve the child_modules by resolving it from my package node_modules folder up to the top library on disk. The child_modules package cannot be found, as it is a devDependency. After that it is trying to find it in an array named core (line 58 in this file), which is feeded by this file. Child_process is marked as a core package, so the package name is just returned without any folder.

In the resolve.js path.dirname is executed on the result of this resolve, which is the package name (child_modules). This results in a "." and is returned to the cumulativeManifestProcessor.js. A "." means the current directory, so it is starting to discoverManifests again from the package.json of my current webpart, which also includes my created library, which is starting this all over again. And so this infinite loop is running untill I close my terminal.

I think the solution is to check if the packageName in Resolve.js is resolved as a directory as I do not know where this browserify core packages are based on. For now I have resolved it by just adding child_process as a normal dependency instead of a devDepedency.

Steps to Reproduce

This is described under Expected or Desired Behavior. Make sure the created library has one of the packages referenced in this file, for example child_process. I think this might also work when simply added to a package.json in the node_modules folder of a webpart, instead of creating a whole new library.

henkterharmsel avatar Nov 08 '18 12:11 henkterharmsel

It should be better you can provide the minimal version of the SPFx library component package and the reproducible project. So more guys can research on this.

Seiyasu avatar Nov 09 '18 07:11 Seiyasu

@Seiyasu I'm sorry. I'm using the 1.6.0 version of all SPFx packages (also the Library component). The project I'm using is an internal one which isn't on Github. After all I also didn't need the child_process module anymore and removed it from this project, so it isn't really a problem for me anymore. I did go through quite some trouble though finding this was the issue, so it might help some other people in the future.

henkterharmsel avatar Nov 16 '18 15:11 henkterharmsel

This issue is being closed as part of an issue list cleanup project. Issues with no activity in the past 6 months that aren't tracked by engineering as bugs were closed as part of this inititive. If this is still an issue, please follow the steps outlined to re-open the issue.

msft-github-bot avatar Jan 22 '20 21:01 msft-github-bot