Skip to content

Local Build Plugin fails with TypeScript: TypeError: value.replace is not a function #5818

Open
@Joroze

Description

@Joroze

Describe the bug

When running a basic build plugin written in TypeScript (via Netlify CLI or through Netlify's build pipeline itself upon deployment), it fails with the following error:

TypeError: value.replace is not a function

I believe the underlying culprit might be the ts-node dependency in this repository. I traced it back to the following issue opened here:

It seems ts-node is no longer maintained.

Steps to reproduce

With a simple build plugin as mentioned in the Netlify docs, but use TypeScript by renaming your file from .js to .ts like so: index.ts

index.ts

export const onPreBuild = async () => {
  console.log('Hello');
};

netlify.toml

[[plugins]]
  package = "./packages/netlify-plugins/my-plugin"

npx netlify build

CLI command and flags

npx netlify build

Configuration

[[plugins]]
  package = "./packages/netlify-plugins/my-plugin"

CLI output

1:18:07 PM: Plugin "./packages/netlify-plugins/my-plugin" internal error
1:18:07 PM: ──────────────────────────────────────────────────────────────────────────────────
1:18:07 PM: ​
1:18:07 PM: Error message
1:18:07 PM: TypeError: value.replace is not a function
1:18:07 PM: ​
1:18:07 PM: Plugin details
1:18:07 PM: Package: ./packages/netlify-plugins/my-plugin
1:18:07 PM: Version: 0.0.0
1:18:07 PM: ​
1:18:07 PM: Error location
1:18:07 PM: While loading "./packages/netlify-plugins/my-plugin" from netlify.toml
1:18:07 PM: at normalizeSlashes (/opt/buildhome/node-deps/node_modules/ts-node/dist/util.js:62:18)
1:18:07 PM: at Object.getExtendsConfigPath (/opt/buildhome/node-deps/node_modules/ts-node/dist/ts-internals.js:24:54)
1:18:07 PM: at readConfig (/opt/buildhome/node-deps/node_modules/ts-node/dist/configuration.js:127:64)
1:18:07 PM: at findAndReadConfig (/opt/buildhome/node-deps/node_modules/ts-node/dist/configuration.js:50:84)
1:18:07 PM: at create (/opt/buildhome/node-deps/node_modules/ts-node/dist/index.js:146:69)
1:18:07 PM: at register (/opt/buildhome/node-deps/node_modules/ts-node/dist/index.js:127:19)
1:18:07 PM: at registerTypeScript (file:///opt/buildhome/node-deps/node_modules/@netlify/build/lib/plugins/child/typescript.js:12:12)
1:18:07 PM: at Object.load (file:///opt/buildhome/node-deps/node_modules/@netlify/build/lib/plugins/child/load.js:11:27)
1:18:07 PM: at handleEvent (file:///opt/buildhome/node-deps/node_modules/@netlify/build/lib/plugins/child/main.js:28:65)
1:18:07 PM: at file:///opt/buildhome/node-deps/node_modules/@netlify/build/lib/plugins/child/main.js:23:63

Environment

System:
OS: macOS 15.1
CPU: (8) arm64 Apple M2
Memory: 72.89 MB / 16.00 GB
Shell: 3.7.1 - /opt/homebrew/bin/fish
Binaries:
Node: 22.6.0 - ~/.local/share/nvm/v22.6.0/bin/node
npm: 10.8.2 - ~/.local/share/nvm/v22.6.0/bin/npm
npmGlobalPackages:
netlify-cli: 17.34.3

Metadata

Metadata

Assignees

No one assigned

    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