Cli: Warnings while parsing netlify.toml file

Created on 1 May 2020  路  2Comments  路  Source: netlify/cli

- Do you want to request a _feature_ or report a _bug_?

Report a bug.

- What is the current behavior?

Running "netlify dev" with a local netlify.toml file that includes a [[redirects]] section results in a runtime error.

Warnings while parsing netlify.toml file:
TypeError: Cannot convert object to primitive value
    at ~/.nvm/versions/node/v12.16.3/lib/node_modules/netlify-cli/src/utils/rules-proxy.js:15:46
    at Array.forEach (<anonymous>)
    at parseFile (~/.nvm/versions/node/v12.16.3/lib/node_modules/netlify-cli/src/utils/rules-proxy.js:14:19)
    at async parseRules (~/.nvm/versions/node/v12.16.3/lib/node_modules/netlify-cli/src/utils/rules-proxy.js:31:22)
    at async createRewriter (~/.nvm/versions/node/v12.16.3/lib/node_modules/netlify-cli/src/utils/rules-proxy.js:68:15)
    at async startProxy (~/.nvm/versions/node/v12.16.3/lib/node_modules/netlify-cli/src/commands/dev/index.js:179:20)
    at async DevCommand.run (~/.nvm/versions/node/v12.16.3/lib/node_modules/netlify-cli/src/commands/dev/index.js:449:19)
    at async DevCommand._run (~/.nvm/versions/node/v12.16.3/lib/node_modules/netlify-cli/node_modules/@oclif/command/lib/command.js:42:20)
    at async Config.runCommand (~/.nvm/versions/node/v12.16.3/lib/node_modules/netlify-cli/node_modules/@oclif/config/lib/config.js:172:9)
    at async Main.run (~/.nvm/versions/node/v12.16.3/lib/node_modules/netlify-cli/node_modules/@oclif/command/lib/main.js:21:9)

I've installed the netlify-cli into the project in an attempt to debug what is going on. When I step through the code, I'm seeing the error is starting with isPlainObj() in the netlify-redirect-parser/common.js file. If change the function to output what is getting passed...

function isPlainObj(o) {
  console.error( "object:", o )
  console.error( "typeof o:", typeof o );
  console.error( "o.constructor:", o.constructor );
  return typeof o == 'object' && o.constructor == Object
}

I see the following output:

object: [Object: null prototype] {
  from: '/api/*',
  to: '/.netlify/functions/:splat',
  status: 200
}
typeof o: object
o.constructor: undefined

Hopefully that gives you a clue to what is going on.

- If the current behavior is a bug, please provide the steps to reproduce.

  1. Create a node.js project
  2. Create a netlify.toml file
  3. Add any [[redirects]] block to the toml file.
[[redirects]]
  from = "/api/*"
  to = "/.netlify/functions/:splat"
  status = 200

- What is the expected behavior?

Netlify dev server starts without error.

- Local Environment Information

  System:
    OS: macOS 10.15.4
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
  Binaries:
    Node: 12.16.3 - ~/.nvm/versions/node/v12.16.3/bin/node
    npm: 6.14.4 - ~/.nvm/versions/node/v12.16.3/bin/npm
  Browsers:
    Chrome: 81.0.4044.129
    Firefox: 75.0
    Safari: 13.1
  npmGlobalPackages:
    netlify-cli: 2.48.0
bug

Most helpful comment

[email protected] has just been released which contains a fix for this issue. Thank you all for your patience!

All 2 comments

@reverentgeek Thank you for reporting this issue. It seems like a bug. I'm wondering how the tests passed because we actually have that include these redirect rules.
This has been fixed in master branch. We're currently block on another issue and will try to release the fixes as soon as possible.
Thanks again!

[email protected] has just been released which contains a fix for this issue. Thank you all for your patience!

Was this page helpful?
0 / 5 - 0 ratings