Skip to content

Warnings while parsing netlify.toml file #872

@reverentgeek

Description

@reverentgeek

- 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

Metadata

Metadata

Assignees

Labels

type: bugcode to address defects in shipped code

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions