Closed yardz closed 3 years ago
Hi @yardz!
Have you added the @babel/plugin-proposal-decorators
plugin?
If that doesn't solve it, a reproduction case would be great.
In fact, actually reproducing the error is quite easy. Just add this code to your controller (src/backend/app/app.controller.ts
):
@Get("/:number")
async findOne(@Param() param) {
return { param }; // You don't even need a return, I put it just to have some return.
}
If you prefer to download the file: app.controller.ts.zip
Then access the endpoint: http://localhost:3000/api/randomNumber/123
The terminal will display this error:
ready - started server on http://localhost:3000
event - compiled successfully
event - build page: /next/dist/pages/_error
wait - compiling...
event - compiled successfully
event - build page: /api/[...catchAll]
wait - compiling...
error - ./src/backend/app/app.controller.ts 11:16
Module parse failed: Unexpected character '@' (11:16)
File was processed with these loaders:
* ./node_modules/next/dist/build/webpack/loaders/next-babel-loader.js
You may need an additional loader to handle the result of these loaders.
| }
|
> async findOne(@Param()
| param) {
| return {
Ps: If you create a service, there is also an error, but I imagine the error is because of the decorators. Probably solving this error will solve the other.
Got it! You need to add babel-plugin-parameter-decorator
:
{
"presets": ["next/babel"],
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": true }],
+ "babel-plugin-parameter-decorator"
]
}
Your example does not work correctly. When you create an endpoint that doesn’t receive parameters, okay, it works, but when you put a decorator inside a function it stops working.
I'm trying to find a way to make everything work correctly, but so far without success