toolsplus / nx-forge

Atlassian Forge plugin for Nx
https://toolsplus.github.io/nx-forge/
MIT License
17 stars 4 forks source link

Deploying with a library throws `Error: Bundling failed: Module not found` #11

Closed itsjxck closed 2 years ago

itsjxck commented 2 years ago

Getting Error: Bundling failed: Module not found: Error: Can't resolve '@better-harvest/harvest-api' in '/Users/jdadam/nx-better-harvest/dist/apps/better-harvest/src' when I try to deploy my app after following the guide.

workspace.json:

{
  "version": 2,
  "projects": {
    "better-harvest": "apps/better-harvest",
    "better-harvest-issue-glance": "apps/better-harvest-issue-glance",
    "harvest-api": "libs/harvest-api"
  }
}

@better-harvest/harvest-api is imported in apps/better-harvest/src/index.ts:

import Resolver from "@forge/resolver";
import harvest from "@better-harvest/harvest-api";

const resolver = new Resolver();

resolver.define("harvest.getProjectAssignments", harvest.getProjectAssignments);

export const handler = resolver.getDefinitions();

nx build better-harvest:

nx-better-harvest on ī‚  main [āœ˜!?] is šŸ“¦ v0.0.0 via ā¬¢ v16.13.1 
āžœ nx build better-harvest

   āœ”    2/2 dependent project tasks succeeded [0 read from cache]

   Hint: you can run the command with --verbose to see the full dependent project outputs

 ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”

> nx run better-harvest:build

Compiling TypeScript files for project "better-harvest"...
Done compiling TypeScript files for project "better-harvest".
Copying better-harvest-issue-glance Custom UI build artifacts...
Done copying better-harvest-issue-glance Custom UI build artifacts.
Patching /Users/jdadam/nx-better-harvest/dist/apps/better-harvest/manifest.yml...
Done patching /Users/jdadam/nx-better-harvest/dist/apps/better-harvest/manifest.yml.
Executor ran for build

 ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”

 >  NX   Successfully ran target build for project better-harvest and 2 task(s) it depends on (18s)

nx deploy better-harvest:

nx-better-harvest on ī‚  main [āœ˜!?] is šŸ“¦ v0.0.0 via ā¬¢ v16.13.1 took 18s 
āžœ nx deploy better-harvest          

> nx run better-harvest:deploy

Running: forge deploy deploy --environment=development
Deploying your app to the development environment.
Press Ctrl+C to cancel.

Running forge lint...
No issues found.

āœ• Deploying your app to development...

ā„¹ Packaging app files

Error: Bundling failed: Module not found: Error: Can't resolve '@better-harvest/harvest-api' in '/Users/jdadam/nx-better-harvest/dist/apps/better-harvest/src'

Rerunning the command with --verbose may give more details.
Exit with error code: 1

 ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”

 >  NX   Running target "better-harvest:deploy" failed

   Failed tasks:

   - better-harvest:deploy

   Hint: run the command with --verbose for more details.
tbinna commented 2 years ago

Thanks, for highlighting this @itsjxck. I managed to reproduce this. I can see at least two issues with this:

  1. I got an error message about flow syntax not being enabled. This seems to be related to no .babelrc file being generated in the library (api) project. I managed to resolve this as suggested in the discussion.
  2. The current Forge app TS build retains the import of '@better-harvest/harvest-api' in the compiled output which cannot be resolved during deployment. This will be a matter of fixing the build to either include the api code as a package or compile it into the app source like the Webpack build for the React app does.
tbinna commented 2 years ago

I think I have a fix for this. The idea is to use the Nx Node Webpack executor instead of the plain TS build executor to make sure dependencies get bundled with the app code. Strangely when testing this with the sample todo app, by analyzing the compiled js file the Forge linter now thinks there are some missing scopes:

/.../forge-todo-app/dist/apps/forge-app/src/index.js
831:34  error    Jira endpoint: POST /rest/api/3/permissions/check requires "read:permission:jira" scope  permission-scope-required

To me, this looks like a bug in the Forge linter. Deploying with --no-verify works.

itsjxck commented 2 years ago

Interesting. What configuration for the webpack executor worked for you?

Edit: Actually, do you mean in the @toolsplus/nx-forge:build executor rather than configuring the executor for the library?

tbinna commented 2 years ago

Currently, the plugin was using the Typescript compilation executor form @nrwl/js. Instead, the PR changes this use the Webpack build from @nrwl/node. You can find the options passed to the Webpack build in the PR. I will have to investigate a bit more on why the linting fails.

github-actions[bot] commented 2 years ago

:tada: This issue has been resolved in version 1.1.2 :tada:

The release is available on:

Your semantic-release bot :package::rocket: