Skip to content

build.base does not resolve relative to flags.cwd #1661

@Munter

Description

@Munter

Describe the bug

When running netlify-build with the --cwd flag to have it use a different directory, the build.base configuration in the discovered config file is resolved relative to the current working directory in the shell instead of the given working directory from --cwd.

I am attempting to test a netlify-build plugin, so I have a bunch of directories each containing a netlify.toml with a different configuration. These are all placed in my test-folder:

$ tree -I node_modules
.
├── lib
│   └── index.js
├── manifest.yml
├── package-lock.json
├── package.json
└── test
    ├── netlify-build.js
    └── no-config
        ├── index.html
        ├── main.css
        └── netlify.toml

In netlify.toml I configure things as if I was running netlify-build from that directory.

Contents of netlify.toml:

[build]
base = "."
publish = "test-dist"

[[plugins]]
package = "../../"

This Is the result:

$ pwd
/Users/pbm/git/netlify-plugin-hashfiles

$ NETLIFY_BUILD_DEBUG=true netlify-build --cwd test/no-config/ --debug

┌─────────────────────────────┐
│        Netlify Build        │
└─────────────────────────────┘

❯ Version
  @netlify/build 3.0.1

❯ Flags
  cwd: test/no-config/
  debug: true

❯ Initial build environment
cwd: test/no-config/
mode: require

❯ UI build settings
build:
  base: test/no-config

❯ Resolved build environment
branch: master
buildDir: /Users/pbm/git/netlify-plugin-hashfiles
configPath: /Users/pbm/git/netlify-plugin-hashfiles/test/no-config/netlify.toml
context: production

❯ Resolved config
build:
  base: /Users/pbm/git/netlify-plugin-hashfiles
  publish: /Users/pbm/git/netlify-plugin-hashfiles/test-dist
plugins:
  - inputs: {}
    origin: config
    package: ../../

❯ Current directory
  /Users/pbm/git/netlify-plugin-hashfiles

❯ Config file
  /Users/pbm/git/netlify-plugin-hashfiles/test/no-config/netlify.toml

❯ Resolved config
  build:
    base: /Users/pbm/git/netlify-plugin-hashfiles
    publish: /Users/pbm/git/netlify-plugin-hashfiles/test-dist
  plugins:
    - inputs: {}
      origin: config
      package: ../../

❯ Context
  production

┌─────────────────────────────┐
│     Configuration error     │
└─────────────────────────────┘

  Error message
  Plugin could not be found using local path: ../../
  Cannot find module '../../'
  Require stack:
  - /Users/pbm/git/netlify-plugin-hashfiles/node_modules/@netlify/build/src/utils/resolve.js
  - /Users/pbm/git/netlify-plugin-hashfiles/node_modules/@netlify/build/src/plugins/resolve.js
  - /Users/pbm/git/netlify-plugin-hashfiles/node_modules/@netlify/build/src/plugins/options.js
  - /Users/pbm/git/netlify-plugin-hashfiles/node_modules/@netlify/build/src/core/main.js
  - /Users/pbm/git/netlify-plugin-hashfiles/node_modules/@netlify/build/src/core/bin.js

  Resolved config
  build:
    base: /Users/pbm/git/netlify-plugin-hashfiles
    publish: /Users/pbm/git/netlify-plugin-hashfiles/test-dist
  plugins:
    - inputs: {}
      origin: config
      package: ../../

Expected behavior:

  • build.base resolved to /Users/pbm/git/netlify-plugin-hashfiles/test/no-config
  • plugins.package resolved to /Users/pbm/git/netlify-plugin-hashfiles (from where package.json main field guides the way)

Actual behavior:

  • build.base resolved to /Users/pbm/git/netlify-plugin-hashfiles
  • plugins.package resolved to /Users/pbm

The build throws because there is nothing node can resolve as an index file in the resolved package directory.

Configuration

  • If possible, please copy/paste below your netlify.toml.

See above

  • Did you run your build through the UI or the CLI?

CLI. But the same thing happens when calling src/core/main.js > build with a similar configuration of cwd

  • If using the CLI, which flags did you use?

See above

  • If using the CLI, please enter the following command in a terminal and copy/paste its output:
npx envinfo --system --binaries --npmPackages @netlify/build,@netlify/config,@netlify/git-utils,@netlify/cache-utils,@netlify/functions-utils,@netlify/run-utils,netlify-cli --npmGlobalPackages @netlify/build,netlify-cli
  System:
    OS: macOS Mojave 10.14.6
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 543.13 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 12.16.0 - ~/.nvm/versions/node/v12.16.0/bin/node
    npm: 6.13.4 - ~/.nvm/versions/node/v12.16.0/bin/npm
  npmPackages:
    @netlify/build: 3.0.1 => 3.0.1
  npmGlobalPackages:
    netlify-cli: 2.53.0

Deploy logs

No deploy logs. This is for local testing of a netlify build plugin

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions