Skip to content

Build fails with “Expected identifier but found ‘import’” using plugin boilerplate #282

@bardaxx

Description

@bardaxx

If you find a security vulnerability, do NOT open an issue. Email [email protected] instead.

Describe the bug

When running the build process with plugin-kit and pkg-utils on a plugin project, the build fails with the error:
[error] Transform failed with 1 error: (define name):1:0: ERROR: Expected identifier but found "import"

This issue occurs even when using the provided boilerplate as a starting point for the plugin.

To Reproduce

Steps to reproduce the behavior:

Steps to reproduce the behavior:

  1. Create a new plugin project using the official boilerplate (sanity-plugin template).
  2. Run npm install to install the dependencies.
  3. Run npm run build.
  4. Observe the error during the build process:

[error] Transform failed with 1 error: (define name):1:0: ERROR: Expected identifier but found "import"

Expected behavior

The build process should complete successfully without throwing an error.

Screenshots
If applicable, add screenshots to help explain your problem.

Which versions of Sanity are you using?

Run sanity versions in the terminal and copy-paste the result here.

What operating system are you using?
macOS Sequoia 15.2
Which versions of Node.js / npm are you running?

Run npm -v && node -v in the terminal and copy-paste the result here.

npm: 10.8.3
node: v22.9.0
Additional context

This issue happens even when using the official boilerplate as a starting point, without any modifications to the provided files. I suspect the issue is related to the handling of import statements in the build process, as the project is set to use CommonJS.

Security issue?

Any security issues should be submitted directly to [email protected]. In order to determine whether you are dealing with a security issue, ask yourself these two questions:

  • Can I access something that's not mine, or something I shouldn't have access to?
  • Can I disable something for other people? If the answer to either of those two questions are "yes", then you're probably dealing with a security issue. Note that even if you answer "no" to both questions, you may still be dealing with a security issue, so if you're unsure, just email us at [[email protected]](mailto:[email protected].

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions