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

Project with a linked module fails with "Module not found" #492

Closed
jansu76 opened this issue Apr 6, 2023 · 1 comment · Fixed by #494
Closed

Project with a linked module fails with "Module not found" #492

jansu76 opened this issue Apr 6, 2023 · 1 comment · Fixed by #494
Assignees

Comments

@jansu76
Copy link

jansu76 commented Apr 6, 2023

Expected Behavior

Buildpack should be able to do npm run build without errors.

Current Behavior

Building with buildpacks, with the example project, fails with "Module not found" error.

Paketo Buildpack for Node Run Script 1.0.4
  Executing build process
    Running 'npm run build'
      
      > reactapp@0.1.0 build
      > react-scripts build
      
      Creating an optimized production build...
      Failed to compile.
      
      Module not found: Error: Can't resolve '@my-dummy-namespace/dummy-component' in '/workspace/src'

Building directly with npm works, npm install, npm run build complete without errors.

Project structure and approach to using linked modules follows this example: https://www.developerway.com/posts/react-project-structure

Possible Solution

Steps to Reproduce

Minimal working example is at https://github.com/jansu76/react-problem
To reproduce error:

  1. checkout
  2. cd reactapp
  3. /build-buildpacks.sh

Motivations

I am unable to use buildpacks to build a larger project which uses this type of linked modules extensively.

@ryanmoran
Copy link
Member

More context from the Slack thread:

I've been able to reproduce the issue and I think I see what the problem is. We aren't really supporting workspaces with what we are doing with the node_modules layer and the symlink indirection. Let me explain.

When you npm install and reference workspaces, the package-lock.json just includes some file path references to where those workspaces are relative to the package-lock.json file. This is fine as long as the node_modules directory stays put. However, in order to make layer caching work well, we are moving the node_modules directory to /layers/paketo-buildpacks_npm-install/build-modules/node_modules and then doing some symlink redirection to make this work. Unfortunately, those file path references in the package-lock.json file are now broken since they were relative to the original location of the node_modules directory.

The solution to this is likely to add more explicit support for workspaces into the npm-install buildpack so that these workspace packages move along with the node_modules directory and their paths don't get messed up.

@ryanmoran ryanmoran transferred this issue from paketo-buildpacks/node-run-script Apr 6, 2023
@ryanmoran ryanmoran self-assigned this Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants