RocketChat / Rocket.Chat.Apps-cli

The CLI for interacting with Rocket.Chat Apps
MIT License
46 stars 27 forks source link

Error while Packaging simple App - The "path" argument must be of type string. Received undefined #126

Closed JNBG closed 1 year ago

JNBG commented 2 years ago

Tried building my first App. Followed the Tutorial here

All went well until adding a Slash Command and then packaging the App. On using the rc-apps deploy Command the App breaks on packaging with following Error:

PS C:\Users\49179\VSCProjects\testapp> rc-apps deploy
   Starting App Deployment to Server

   Getting Server Info... ✓
   Packaging the app... -
 > ../../AppData/Roaming/npm/node_modules/@rocket.chat/apps-cli/node_modules/@rocket.chat/apps-compiler/bundler/esbuild.js:47:92: error: [plugin: apps-engine] The "path" argument must be of type string. Received undefined
    47 │                         if (!/@rocket\.chat\/apps-engine/.test(args.path) && path_1.default.isAbsolute(nodeModulePath)) {
       ╵                                                                                             ^
    at validateString (internal/validators.js:120:11)
    at Object.isAbsolute (path.js:353:5)
    at C:\Users\49179\AppData\Roaming\npm\node_modules\@rocket.chat\apps-cli\node_modules\@rocket.chat\apps-compiler\bundler\esbuild.js:47:93
    at callback (C:\Users\49179\AppData\Roaming\npm\node_modules\@rocket.chat\apps-cli\node_modules\esbuild\lib\main.js:814:34)
    at handleRequest (C:\Users\49179\AppData\Roaming\npm\node_modules\@rocket.chat\apps-cli\node_modules\esbuild\lib\main.js:646:36)
    at handleIncomingPacket (C:\Users\49179\AppData\Roaming\npm\node_modules\@rocket.chat\apps-cli\node_modules\esbuild\lib\main.js:701:7)
    at Socket.readFromStdout (C:\Users\49179\AppData\Roaming\npm\node_modules\@rocket.chat\apps-cli\node_modules\esbuild\lib\main.js:578:7)
    at Socket.emit (events.js:315:20)
    at addChunk (_stream_readable.js:295:12)
    at readableAddChunk (_stream_readable.js:271:9)

   ../../AppData/Roaming/npm/node_modules/@rocket.chat/apps-cli/node_modules/@rocket.chat/apps-compiler/bundler/esbuild.js:35:26: note: This error came from the "onResolve" callback registered here   
    35 │                     build.onResolve({ filter: /.*/ }, async (args) => {
       ╵                           ~~~~~~~~~
    at setup (C:\Users\49179\AppData\Roaming\npm\node_modules\@rocket.chat\apps-cli\node_modules\@rocket.chat\apps-compiler\bundler\esbuild.js:35:27)
    at handlePlugins (C:\Users\49179\AppData\Roaming\npm\node_modules\@rocket.chat\apps-cli\node_modules\esbuild\lib\main.js:738:23)
    at Object.buildOrServe (C:\Users\49179\AppData\Roaming\npm\node_modules\@rocket.chat\apps-cli\node_modules\esbuild\lib\main.js:1026:7)
    at C:\Users\49179\AppData\Roaming\npm\node_modules\@rocket.chat\apps-cli\node_modules\esbuild\lib\main.js:1801:17
    at new Promise (<anonymous>)
    at Object.build (C:\Users\49179\AppData\Roaming\npm\node_modules\@rocket.chat\apps-cli\node_modules\esbuild\lib\main.js:1800:14)
    at Object.build (C:\Users\49179\AppData\Roaming\npm\node_modules\@rocket.chat\apps-cli\node_modules\esbuild\lib\main.js:1655:51)
    at AppsCompiler.bundleCompilation [as bundler] (C:\Users\49179\AppData\Roaming\npm\node_modules\@rocket.chat\apps-cli\node_modules\@rocket.chat\apps-compiler\bundler\esbuild.js:14:41)
    at AppsCompiler.bundle (C:\Users\49179\AppData\Roaming\npm\node_modules\@rocket.chat\apps-cli\node_modules\@rocket.chat\apps-compiler\AppsCompiler.js:41:45)

   LiftoffApp.js:5:26: note: The plugin "apps-engine" was triggered by this import
     5 │ const liftoff_1 = require("./commands/liftoff");
       ╵                           ~~~~~~~~~~~~~~~~~~~~
Error: Cannot find module './commands/liftoff'
Require stack:
- C:\Users\49179\VSCProjects\testapp/app.json
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:15)
    at Function.resolve (internal/modules/cjs/helpers.js:78:19)
)
    at C:\Users\49179\AppData\Roaming\npm\node_modules\@rocket.chat\apps-cli\node_modules\@rocket.chat\apps-compiler\bundler\esbuild.js:46:58
    at callback (C:\Users\49179\AppData\Roaming\npm\node_modules\@rocket.chat\apps-cli\node_modules\esbuild\lib\main.js:814:34)
    at handleRequest (C:\Users\49179\AppData\Roaming\npm\node_modules\@rocket.chat\apps-cli\node_modules\esbuild\lib\main.js:646:36)
    at handleIncomingPacket (C:\Users\49179\AppData\Roaming\npm\node_modules\@rocket.chat\apps-cli\node_modules\esbuild\lib\main.js:701:7)
    at Socket.readFromStdout (C:\Users\49179\AppData\Roaming\npm\node_modules\@rocket.chat\apps-cli\node_modules\esbuild\lib\main.js:578:7)
    at Socket.emit (events.js:315:20)
  code: 'MODULE_NOT_FOUND',
  requireStack: [ 'C:\\Users\\49179\\VSCProjects\\testapp/app.json' ]
}
   Packaging the app... ✖
 »   Error:    ⟿  Build failed with 1 error:
 »   ../../AppData/Roaming/npm/node_modules/@rocket.chat/apps-cli/node_modules/@rocket.chat/apps-compiler/bundler/esbuild.js:47:92: error: [plugin: apps-engine] The "path" argument must be of type    
 »   string. Received undefined

Whenever I remove the part where it's extending the Configuration for the Slash Command everything runs well and get's uploaded to my test-server.

    protected async extendConfiguration(configuration: IConfigurationExtend): Promise<void> {
        await configuration.slashCommands.provideSlashCommand(new LiftoffCommand(this));
    }

The LiftoffCommand is 1:1 Copy from the Tutorial.

I am running this on: @rocket.chat/apps-cli/1.10.1 win32-x64 node-v12.18.1

You can find a reproduction Repo here

jayeshdesai4520 commented 2 years ago

@JNBG Hello, is there any fix? did you find it?

JNBG commented 2 years ago

@jayeshdesai4520 so far no - but I didn't really find the time to work on it yet

bk201- commented 2 years ago

It seems I found a problemed code. It's in "bundler/esbuild.ts"

This function works on Linux, however doesn't work on Windows.

function normalizeAppModulePath(modulePath: string, parentDir: string): string {
    return /\.\.?\//.test(modulePath)
        ? path.resolve('/', path.dirname(parentDir), modulePath).substring(1).concat('.js')
        : modulePath;
}
bk201- commented 2 years ago

Hi!

Please see my PR that fixes this problem https://github.com/RocketChat/Rocket.Chat.Apps-compiler/pull/47