plugin must be a function or a promise error
🐛 Bug Report
After installing fastify-cli and running with command npm start getting error which is written below. if i am running server with normal command node server.js my server running well
Getting error
[email protected] start C:\Users\Aditya_kumar\Desktop\demo_classes\fastify
> fastify start server.js
Error: plugin must be a function or a promise
at assertPlugin (C:\Users\Aditya_kumar\Desktop\demo_classes\fastify\node_modules\avvio\boot.js:200:11)
at Boot._addPlugin (C:\Users\Aditya_kumar\Desktop\demo_classes\fastify\node_modules\avvio\boot.js:233:12)
at Boot.use (C:\Users\Aditya_kumar\Desktop\demo_classes\fastify\node_modules\avvio\boot.js:209:25)
at Object.server.<computed> [as register] (C:\Users\Aditya_kumar\Desktop\demo_classes\fastify\node_modules\avvio\boot.js:33:14)
at runFastify (C:\Users\Aditya_kumar\Desktop\demo_classes\fastify\node_modules\fastify-cli\start.js:128:17)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `fastify start server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Aditya_kumar\AppData\Roaming\npm-cache\_logs\2021-03-04T04_52_44_630Z-debug.log
Expected behavior
A clear and concise description of what you expected to happen.
// server is running
Your Environment
- node version: 14, 16, 0
- fastify version: >=3.13.0
- fastify version: >=2.8.0
- os: Windows
What is the content of server.js?
content of server.js file
const fastify = require('fastify');
const app = fastify({logger: true});
// register routes
const rou = require("./routes/firstRoutes");
app.register(rou);
const start = async function(){
try{
await app.listen("3000")
}catch(e){
app.log.error(e);
}
}
start();
and content of routes/firstRoutes.js
async function hell(app, options) {
app.get('/', async (req, res) => {
return {"greeting":"hello"};
});
app.get("/user", async (req, rep) =>{
return {"user":"he all she"};
});
};
module.exports = hell;
If you read the docs, https://github.com/fastify/fastify-cli#start shows that you need to point it to a plugin to start, not a server. You can start the server just by using node server.
so, fastify start filename.js for only plugins start
yes!
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.