Can't build LPWAN Server

I followed Install doc and made Lora Server installed and run successfully. But I got an error when I tried to build LPWAN server using

$ docker-compose -f development/docker-compose.yml up --build

Error: Cannot find module ‘…/generated/prisma-client’ as below. Any help is highly appreciated.

lpwanserver_1 |
lpwanserver_1 | > lpwanserver-rest@1.2.1 dev /usr/src
lpwanserver_1 | > nodemon app/index.js --watch app
lpwanserver_1 |
lpwanserver_1 | [nodemon] 1.19.1
lpwanserver_1 | [nodemon] to restart at any time, enter rs
lpwanserver_1 | [nodemon] watching: /usr/src/app/**/*
lpwanserver_1 | [nodemon] starting node app/index.js
lpwanserver_1 | error: uncaughtException: Cannot find module ‘…/generated/prisma-client’
lpwanserver_1 | Error: Cannot find module ‘…/generated/prisma-client’
lpwanserver_1 | at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
lpwanserver_1 | at Function.Module._load (internal/modules/cjs/loader.js:508:25)
lpwanserver_1 | at Module.require (internal/modules/cjs/loader.js:637:17)
lpwanserver_1 | at require (internal/modules/cjs/helpers.js:22:18)
lpwanserver_1 | at Object. (/usr/src/app/lib/prisma.js:7:22)
lpwanserver_1 | at Module._compile (internal/modules/cjs/loader.js:701:30)
lpwanserver_1 | at Object.Module._extensions…js (internal/modules/cjs/loader.js:712:10)
lpwanserver_1 | at Module.load (internal/modules/cjs/loader.js:600:32)
lpwanserver_1 | at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
lpwanserver_1 | at Function.Module._load (internal/modules/cjs/loader.js:531:3) {“error”:{“code”:“MODULE_NOT_FOUND”},“stack”:“Error: Cannot find module ‘…/generated/prisma-client’\n at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)\n at Function.Module._load (internal/modules/cjs/loader.js:508:25)\n at Module.require (internal/modules/cjs/loader.js:637:17)\n at require (internal/modules/cjs/helpers.js:22:18)\n at Object. (/usr/src/app/lib/prisma.js:7:22)\n at Module._compile (internal/modules/cjs/loader.js:701:30)\n at Object.Module._extensions…js (internal/modules/cjs/loader.js:712:10)\n at Module.load (internal/modules/cjs/loader.js:600:32)\n at tryModuleLoad (internal/modules/cjs/loader.js:539:12)\n at Function.Module._load (internal/modules/cjs/loader.js:531:3)”,“exception”:true,“date”:"Sun Sep 15 2019 19:30:12 GMT+0000 (Coordinated Universal

There is a script to manage the development database, which needs to be started before the LPWAN Server starts. Look at the script “development/bin/manage-db”. First boot the DB with “./development/bin/manage-db start”. Next, deploy the models to the DB with “./development/bin/mange-db deploy”. The deployment step generates the the DB client, which will resolve the missing module error.

There’s more info about running the development environment here:

The docs aren’t explicit that the deploy step needs to happen before starting LPWAN Server. I’ll make an issue to update the docs.

Thanks, I successfully executed “./development/bin/mange-db deploy” without errors. After run “$ docker-compose -f development/docker-compose.yml up --build” , the error "Cannot find module ‘…/generated/prisma-client’ has gone. But I got the following errors:

lpwanserver_1 | error: Failed to add Express middleware to serve UI. Set public_dir to empty string to avoid error.ENOENT: no such file or directory, access ‘/usr/src/app/generated/public/index.html’ {“service”:“lpwanserver”,“errno”:-2,“syscall”:“access”,“code”:“ENOENT”,“path”:"/usr/src/app/generated/public/index.html",“stack”:“Error: ENOENT: no such file or directory, access ‘/usr/src/app/generated/public/index.html’\n at Object.accessSync (fs.js:192:3)\n at serveSpa (/usr/src/app/lib/serve-spa.js:10:6)\n at createApp (/usr/src/app/express-app.js:29:7)\n at main (/usr/src/app/index.js:24:21)\n at Object. (/usr/src/app/index.js:47:1)\n at Module._compile (internal/modules/cjs/loader.js:701:30)\n at Object.Module._extensions…js (internal/modules/cjs/loader.js:712:10)\n at Module.load (internal/modules/cjs/loader.js:600:32)\n at tryModuleLoad (internal/modules/cjs/loader.js:539:12)\n at Function.Module._load (internal/modules/cjs/loader.js:531:3)\n at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)\n at startup (internal/bootstrap/node.js:283:19)\n at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)”}
lpwanserver_1 | error: Error: ENOENT: no such file or directory, access ‘/usr/src/app/generated/public/index.html’ {“errno”:-2,“syscall”:“access”,“code”:“ENOENT”,“path”:"/usr/src/app/generated/public/index.html",“service”:“lpwanserver”}

I just fixed it in the master branch, so if you pull the repo it should be resolved. The fix was to add an empty public_dir environment variable to the development docker-compose file. I thought that was already there, but it wasn’t. This let’s the server know not to serve the UI, which is missing until it’s built. Generally in development you would run the webpack development server to serve the UI, but if you want to develop the back-end with a static UI, you could run the build-ui script (bin/build-ui), and then remove the “public_dir” env variable from development/docker-compose.yaml. That would require pulling the web-client repo and placing it next to the lpwanserver folder.

If you haven’t yet, generate development certificates by running “./development/bin/generate-development-certificates”. If the certs are there, there should be no more errors when you start server for development.

1 Like

not sure what else you also changed. After pull the repo, I got the first problem again:Cannot find module ‘…/generated/prisma-client’. I am very sure I run “./development/bin/mange-db deploy” without error.

Successfully built d5baf0172dc5
Successfully tagged development_lpwanserver:latest
Creating development_lpwanserver_1 … done
Attaching to development_lpwanserver_1
lpwanserver_1 |
lpwanserver_1 | > lpwanserver-rest@1.2.1 dev /usr/src
lpwanserver_1 | > nodemon app/index.js --watch app
lpwanserver_1 |
lpwanserver_1 | [nodemon] 1.19.1
lpwanserver_1 | [nodemon] to restart at any time, enter rs
lpwanserver_1 | [nodemon] watching: /usr/src/app/**/*
lpwanserver_1 | [nodemon] starting node app/index.js
lpwanserver_1 | error: uncaughtException: Cannot find module ‘…/generated/prisma-client’
lpwanserver_1 | Error: Cannot find module ‘…/generated/prisma-client’
lpwanserver_1 | at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
lpwanserver_1 | at Function.Module._load (internal/modules/cjs/loader.js:508:25)
lpwanserver_1 | at Module.require (internal/modules/cjs/loader.js:637:17)
lpwanserver_1 | at require (internal/modules/cjs/helpers.js:22:18)
lpwanserver_1 | at Object. (/usr/src/app/lib/prisma.js:7:22)
lpwanserver_1 | at Module._compile (internal/modules/cjs/loader.js:701:30)
lpwanserver_1 | at Object.Module._extensions…js (internal/modules/cjs/loader.js:712:10)
lpwanserver_1 | at Module.load (internal/modules/cjs/loader.js:600:32)
lpwanserver_1 | at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
lpwanserver_1 | at Function.Module._load (internal/modules/cjs/loader.js:531:3) {“error”:{“code”:“MODULE_NOT_FOUND”},“stack”:“Error: Cannot find module ‘…/generated/prisma-client’\n at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)\n at Function.Module._load (internal/modules/cjs/loader.js:508:25)\n at Module.require (internal/modules/cjs/loader.js:637:17)\n at require (internal/modules/cjs/helpers.js:22:18)\n at Object. (/usr/src/app/lib/prisma.js:7:22)\n at Module._compile (internal/modules/cjs/loader.js:701:30)\n at Object.Module._extensions…js (internal/modules/cjs/loader.js:712:10)\n at Module.load (internal/modules/cjs/loader.js:600:32)\n at tryModuleLoad (internal/modules/cjs/loader.js:539:12)\n at Function.Module._load (internal/modules/cjs/loader.js:531:3)”,“exception”:true,“date”:“Wed Sep 18 2019 00:05:30 GMT+0000 (Coordinated Universal Time)”,“process”:{“pid”:30,“uid”:0,“gid”:0,“cwd”:"/usr/src",“execPath”:"/usr/local/bin/node",“version”:“v10.15.3”,“argv”:["/usr/local/bin/node","/usr/src/app/index.js"],“memoryUsage”:{“rss”:52146176,“heapTotal”:25411584,“heapUsed”:15084120,“external”:162697}},“os”:{“loadavg”:[1.080078125,0.4501953125,0.1806640625],“uptime”:430807},“trace”:[{“column”:15,“file”:“internal/modules/cjs/loader.js”,“function”:“Module._resolveFilename”,“line”:582,“method”:"_resolveFilename",“native”:false},{“column”:25,“file”:“internal/modules/cjs/loader.js”,“function”:“Module._load”,“line”:508,“method”:"_load",“native”:false},{“column”:17,“file”:“internal/modules/cjs/loader.js”,“function”:“Module.require”,“line”:637,“method”:“require”,“native”:false},{“column”:18,“file”:“internal/modules/cjs/helpers.js”,“function”:“require”,“line”:22,“method”:null,“native”:false},{“column”:22,“file”:"/usr/src/app/lib/prisma.js",“function”:null,“line”:7,“method”:null,“native”:false},{“column”:30,“file”:“internal/modules/cjs/loader.js”,“function”:“Module._compile”,“line”:701,“method”:"_compile",“native”:false},{“column”:10,“file”:“internal/modules/cjs/loader.js”,“function”:“Module._extensions…js”,“line”:712,“method”:".js",“native”:false},{“column”:32,“file”:“internal/modules/cjs/loader.js”,“function”:“Module.load”,“line”:600,“method”:“load”,“native”:false},{“column”:12,“file”:“internal/modules/cjs/loader.js”,“function”:“tryModuleLoad”,“line”:539,“method”:null,“native”:false},{“column”:3,“file”:“internal/modules/cjs/loader.js”,“function”:“Module._load”,“line”:531,“method”:"_load",“native”:false}],“service”:“lpwanserver”}
lpwanserver_1 | [nodemon] app crashed - waiting for file changes before starting…

can’t find /usr/src/app/… maybe "/usr/src " problem?

The DB deploy command will generate the DB client assuming that it’s an initial deployment or there was a change to the models. The issue is that the generated DB client folder was removed, but the docker volume for the DB persisted, so the deploy command didn’t generate the client.

You have 2 options.

  1. Remove the docker volume for the DB so that the deploy command will generate the client.
./development/bin/manage-db stop
npm run clean
./development/bin/manage-db start
./development/bin/manage-db deploy
  1. There’s a separate command to generate the DB client, if the DB is running and the models have already been deployed.
export primsa_url="http://localhost:4466/lpwanserver/dev"
npm run prisma -- generate

Sorry for the complexity. I introduced Prisma because I thought it would reduce development complexity, but it has had the opposite effect.

Above errors were removed after applying option 2, but got below additional errors:

Successfully built d5baf0172dc5
Successfully tagged development_lpwanserver:latest
development_lpwanserver_1 is up-to-date
Attaching to development_lpwanserver_1
lpwanserver_1 |
lpwanserver_1 | > lpwanserver-rest@1.2.1 dev /usr/src
lpwanserver_1 | > nodemon app/index.js --watch app
lpwanserver_1 |
lpwanserver_1 | [nodemon] 1.19.1
lpwanserver_1 | [nodemon] to restart at any time, enter rs
lpwanserver_1 | [nodemon] watching: /usr/src/app/**/*
lpwanserver_1 | [nodemon] starting node app/index.js
lpwanserver_1 | error: FetchError: request to http://127.0.0.1:4466/lpwanserver/dev failed, reason: connect ECONNREFUSED 127.0.0.1:4466 {“type”:“system”,“errno”:“ECONNREFUSED”,“code”:“ECONNREFUSED”,“statusCode”:400,“status”:400,“service”:“lpwanserver”}
lpwanserver_1 | [nodemon] restarting due to changes…
lpwanserver_1 | [nodemon] starting node app/index.js

I’m guessing that docker-compose picked up the environment variable exported in option 2 above. Try running in a new terminal tab. That URL is set by the prisma_url value in “development/config.json”. It should use “prisma” as the host name to match the docker service. If running in a new tab doesn’t work, then the DB client was generated with a hard-coded URL. In any case, try running these steps in a new tab and see if that works.

# only if you don't have any local volumes that you want to keep
docker system prune --force --volumes
./development/manage-db start
./development/manage-db deploy
# optionally start LoRa Server
docker-compose -f development/loraserver/docker-compose.yml up -d
# start lpwan server
docker-compose -f development/docker-compose up --build

I should note that in addition to deploying the models and generating the DB client, the deploy command is also seeding the DB with required data. There’s a separate command for that as well, which is the reset command in the manage-db script.

After executed as your recommended above, the results are below.

Some notes:
127.0.0.1:4466 is set in prisma/prisma.yml, is it correct?

endpoint: ‘http://127.0.0.1:4466
datamodel: ./versions/v1/datamodel.prisma


Errors:

Successfully built d5baf0172dc5
Successfully tagged development_lpwanserver:latest
development_lpwanserver_1 is up-to-date
Attaching to development_lpwanserver_1
lpwanserver_1 |
lpwanserver_1 | > lpwanserver-rest@1.2.1 dev /usr/src
lpwanserver_1 | > nodemon app/index.js --watch app
lpwanserver_1 |
lpwanserver_1 | [nodemon] 1.19.1
lpwanserver_1 | [nodemon] to restart at any time, enter rs
lpwanserver_1 | [nodemon] watching: /usr/src/app/**/*
lpwanserver_1 | [nodemon] starting node app/index.js
lpwanserver_1 | error: FetchError: request to http://127.0.0.1:4466/ failed, reason: connect ECONNREFUSED 127.0.0.1:4466 {“type”:“system”,“errno”:“ECONNREFUSED”,“code”:“ECONNREFUSED”,“statusCode”:400,“status”:400,“service”:“lpwanserver”}

Is “endpoint” correct?

or
endpoint: ‘http://prisma:4466

The correct endpoint is http://prisma:4466/lpwanserver/dev.

prisma/prisma.yml should read:
endpoint: ${env:prisma_url}

This causes causes the generated DB client to attempt to connect to process.env.prisma_url. You can check if the client was generated correctly by viewing app/generated/prisma-client/index.js. Towards the bottom of the file, you should see process.env.prisma_url. The development/docker-compose file sets the config file to development/config.json. In that file, the prisma_url is set to http://prisma:4466/lpwanserver/dev. All config variables can be overwritten with environment variables, but in case prisma_url comes from a config file and not an environment variable, the module app/config/index.js writes the value of config.prisma_url to process.env.prisma_url so that it can be used by the DB client.

Great. Build LPWAN Server successfully, When I execute
https://x.x.x.x:3200 in the browser, I got the below:

Cannot GET /

Certificate problem?

Server logs:
lpwanserver_1 | info: GET / 404 139 - 0.716 ms {“service”:“lpwanserver”}
lpwanserver_1 | info: GET / 404 139 - 0.667 ms {“service”:“lpwanserver”}

This site is not secure

This might mean that someone’s trying to fool you or steal any info you send to the server. You should close this site immediately.

Go to your Start page

[ Details ](javascript:expandCollapseDetails(‘infoBlockID’):wink:

Your PC doesn’t trust this website’s security certificate.
The hostname in the website’s security certificate differs from the website you are trying to visit.

Error Code: DLG_FLAGS_INVALID_CA
DLG_FLAGS_SEC_CERT_CN_INVALID

Go on to the webpage (Not recommended)

I import certs/ca-crt.pem into your browser’s certificates management settings.

Great! Glad to hear the development build is working. Importing the ca cert into the browser is correct. The server runs at 3200, but unless the web-client is built before starting the server, the root URL will return a 404. You can test the REST api at /api, or you can build the web client before starting the server. In this case, make sure to remove the public_api=’’ environment variable that we set earlier, so that the app will serve the UI. You can also run the development server for the web client, which runs at 3000 and hits the API running at 3200.

I used build web-client in my site with “git clone https://github.com/cablelabs/lpwanserver-web-client.git” and run “/bin/build-ui” before build sever. In this way, my web-client works with https://x.x.x.x:3200. But Rest api doesn’t with “/api”. get error:“Cannot GET /api”.

All the REST endpoints begin with /api, but there is not currently an /api endpoint that returns info about the api.