balena-io / pinejs

Generate rest APIs from natural language models
Apache License 2.0
63 stars 11 forks source link

Path Error with Custom Server Code #214

Closed kewp closed 6 years ago

kewp commented 6 years ago

After following the getting started guide I'm getting a Cannot find module error when running npm start

C:\Users\Karl\tst\prices>npm start

> prices@1.0.0 start C:\Users\Karl\tst\prices
> coffee src/index.coffee src

body-parser deprecated bodyParser: use individual json/urlencoded middlewares src\index.coffee:12:11
body-parser deprecated undefined extended: provide extended option node_modules\body-parser\index.js:105:29
Sucessfully executed standard models.
Successfully executed migrations model.
Loading application config
Loading JSON: src\config.json
Auth: Insert ID:  actor 12
Auth: Insert ID:  user 12
Successfully executed Undercurrent model.
Error loading application config { Error: Error loading custom server code: 'Cannot find module 'src/app.coffee''
    at Function.Module._resolveFilename (module.js:548:15)
    at Function.Module._load (module.js:475:25)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Promise.map (C:\Users\Karl\tst\prices\node_modules\@resin\pinejs\src\config-loader\config-loader.ts:179:22)
    at tryCatcher (C:\Users\Karl\tst\prices\node_modules\bluebird\js\release\util.js:16:23)
    at MappingPromiseArray._promiseFulfilled (C:\Users\Karl\tst\prices\node_modules\bluebird\js\release\map.js:61:38)
    at MappingPromiseArray.PromiseArray._iterate (C:\Users\Karl\tst\prices\node_modules\bluebird\js\release\promise_array.js:114:31)
    at MappingPromiseArray.init (C:\Users\Karl\tst\prices\node_modules\bluebird\js\release\promise_array.js:78:10)
    at MappingPromiseArray._asyncInit (C:\Users\Karl\tst\prices\node_modules\bluebird\js\release\map.js:30:10)
    at _drainQueueStep (C:\Users\Karl\tst\prices\node_modules\bluebird\js\release\async.js:142:12)
    at _drainQueue (C:\Users\Karl\tst\prices\node_modules\bluebird\js\release\async.js:131:9)
    at Async._drainQueues (C:\Users\Karl\tst\prices\node_modules\bluebird\js\release\async.js:147:5)
    at Immediate.Async.drainQueues (C:\Users\Karl\tst\prices\node_modules\bluebird\js\release\async.js:17:14)
    at runCallback (timers.js:810:20)
    at tryOnImmediate (timers.js:768:5)
    at processImmediate [as _immediateCallback] (timers.js:745:5) code: 'MODULE_NOT_FOUND' } Error: Error loading custom

This is my config.json

{
    "models": [{
        "modelName": "Undercurrent",
        "modelFile": "undercurrent.sbvr",
        "apiRoot": "data",
        "customServerCode": "app.coffee"
    }],
    "users": [{
        "username": "guest",
        "password": " "
    }]
}

My start script in package.json is "start": "./node_modules/.bin/coffee src/index.coffee src".

Here is my tree:

|-- README.md
|-- node_modules
|-- package-lock.json
|-- package.json
|-- src
|    |-- app.coffee
|    |-- config.json
|    |-- index.coffee
|    |-- undercurrent.sbvr
Page- commented 6 years ago

Hey @kewp, it should work if you specify an absolute path and should also be fixed by https://github.com/resin-io/pinejs/pull/215 - you should be able to try that PR out by pointing your package.json @resin/pinejs entry to github:resin-io/pinejs#resolve-relative-path and running an npm install, although I expect it will also be merged/published soon

kewp commented 6 years ago

That seems to have fixed it. Thanks @Page-

Page- commented 6 years ago

Fixed in v8.4.2