I want to use redirects in gatsby. I installed netlify-cli and added netlify.toml file in the root folder.
In netlify-toml file
[[redirects]]
from = “/search/*”
to = “/search”
status = 200
When I run netlify dev, I’ve got this following errors.
Warnings while parsing netlify.toml file:
TypeError: Cannot convert object to primitive value
at ~/npm-global/lib/node_modules/netlify-cli/src/utils/rules-proxy.js:15:46
at Array.forEach ()
at parseFile (~/npm-global/lib/node_modules/netlify-cli/src/utils/rules-proxy.js:14:19)
at async parseRules (~/npm-global/lib/node_modules/netlify-cli/src/utils/rules-proxy.js:31:22)
at async createRewriter (~/npm-global/lib/node_modules/netlify-cli/src/utils/rules-proxy.js:68:15)
at async startProxy (~/npm-global/lib/node_modules/netlify-cli/src/commands/dev/index.js:179:20)
at async DevCommand.run (~/npm-global/lib/node_modules/netlify-cli/src/commands/dev/index.js:449:19)
at async DevCommand._run (~/npm-global/lib/node_modules/netlify-cli/node_modules/@oclif/command/lib/command.js:42:20)
at async Config.runCommand (~/npm-global/lib/node_modules/netlify-cli/node_modules/@oclif/config/lib/config.js:172:9)
at async Main.run (~/npm-global/lib/node_modules/netlify-cli/node_modules/@oclif/command/lib/main.js:21:9)
I removed [[redirects]] and it’s working. So I added [[redirects]] again to test it and it’s working. I am new to this. I am sorry I cannot provide any informative data. Thanks.
I can confirm this issue.
Now running: netlify-cli/2.48.0 darwin-x64 node-v13.11.0
By removing the redirects the issue is gone. With the previous netlify-cli version (sorry, I don’t know which version I was on) this wasn’t the case.
[build]
functions = "src/functions/"
[dev]
command = "gatsby develop"
port = 3000
[[redirects]]
from = "/post"
to = "/.netlify/functions/post"
status = 200
[[redirects]]
from = "/vuistje/*"
to = "/show?id=:splat"
status = 302
I’m also facing the same issue and the same error as minheinkhant, I recently installed the netlify-cli (current tags 2.48.0) but the error still persist even i remove the [[redirects]] and added it back. Please consult. Thanks
...
Connected!
Waiting for localhost:34567.
Connected!
◈ Warnings while parsing netlify.toml file:
TypeError: Cannot convert object to primitive value
at result.errors.forEach.err (~/.nvm/versions/node/v10.19.0/lib/node_modules/netlify-cli/src/utils/rules-proxy.js:15:46)
at Array.forEach (<anonymous>)
at parseFile (~/.nvm/versions/node/v10.19.0/lib/node_modules/netlify-cli/src/utils/rules-proxy.js:14:19)
netlify.toml file:
# Settings in the [build] context are global and are applied to all contexts
# unless otherwise overridden by more specific contexts.
[build]
# Directory to change to before starting a build.
# This is where we will look for package.json/.nvmrc/etc.
# base = "project/"
# Directory (relative to root of your repo) that contains the deploy-ready
# HTML files and assets generated by the build. If a base directory has
# been specified, include it in the publish directory path.
publish = "public"
# Directory with the serverless Lambda functions to deploy to AWS.
functions = "public/lambda"
# Default build command.
command = "yarn build"
# Directory with the serverless Lambda functions to deploy to AWS.
# functions = "project/functions/"
# A redirect rule with all the supported properties
[[redirects]]
from = "/index.html"
to = "/"
[[redirects]]
from = "/application.html"
to = "/project/"
@samajammin, @minheinkhant Thank you reporting this problem. We’ve just released a new version that contains a fix for this problem. Please upgrade to latest version npm i -g netlify-cli@latest and let us know if it is still an issue.
@raeesbhatti just updated to netlify-cli/2.49.0 win32-x64 node-v10.16.3 and found that I am still getting a TypeError from rules-proxy.js when I include [[redirects]] in my netlify.toml file.
This was hard to reproduce but I was able to track it down. The error is coming from a dependency which has been patched. There’s a PR to upgrade the dependencies in netlify-cli.
It might be worth trying to install netlify-cli globally again using npm i -g netlify-cli@latest, since we’re using ^ dependencies, npm should pick up the new versions. If it doesn’t work, please hold on until we release a new version. I’ll upgrade this thread when we do.
I’m confirming that after installing netlify-cli@2.49.0, the issue is resolved for me. I’m able to start my project with netlify dev with:
[[redirects]]
from = "/api/*"
to = "/.netlify/functions/:splat"
status = 200
in netlify.toml, without the TypeError: Cannot convert object to primitive value error that was reported earlier. Thanks for taking quick action on this!