Skip to content

compiler package doesn't declare browserlists dependency and crashes if it isn't installed #3089

@paperclover

Description

@paperclover

Marko Version

Upgraded @marko/compiler from 5.39.40 to 5.39.40 (latest versions)

Details

mkdir new_project
cd new_project
npm init -y

npm i marko@latest @marko/compiler@latest
echo 'import * as marko from "@marko/compiler";
const compiled = marko.compileSync(`<h1 />`, "yawn.marko", {});
console.log(compiled);' > demo.mjs

node demo.mjs

Expected Behavior

it works

Actual Behavior

/Users/clo/code/marko_bug/node_modules/@marko/compiler/dist/babel.js:46411
const configFile = options.configFile || process.env.BROWSERSLIST_CONFIG || _browserslist.findConfigFile(configPath);
^

TypeError: Cannot read properties of undefined (reading 'findConfigFile')
at getTargets (/Users/clo/code/marko_bug/node_modules/@marko/compiler/dist/babel.js:46411:95)
at resolveTargets (/Users/clo/code/marko_bug/node_modules/@marko/compiler/dist/babel.js:46484:50)
at loadPrivatePartialConfig (/Users/clo/code/marko_bug/node_modules/@marko/compiler/dist/babel.js:47717:49)
at loadPrivatePartialConfig.next ()
at loadPartialConfig (/Users/clo/code/marko_bug/node_modules/@marko/compiler/dist/babel.js:47746:25)
at loadPartialConfig.next ()
at evaluateSync (/Users/clo/code/marko_bug/node_modules/@marko/compiler/dist/babel.js:42960:26)
at sync (/Users/clo/code/marko_bug/node_modules/@marko/compiler/dist/babel.js:42867:12)
at stopHiding - secret - don't use this - v1 (/Users/clo/code/marko_bug/node_modules/@marko/compiler/dist/babel.js:43462:11)
at loadPartialConfigSync (/Users/clo/code/marko_bug/node_modules/@marko/compiler/dist/babel.js:48055:84)
at loadPartialConfig (/Users/clo/code/marko_bug/node_modules/@marko/compiler/dist/babel.js:48060:15)
at loadBabelConfigSync (/Users/clo/code/marko_bug/node_modules/@marko/compiler/dist/index.js:87:32)
at Module.compileSync (/Users/clo/code/marko_bug/node_modules/@marko/compiler/dist/index.js:36:23)
at file:///Users/clo/code/marko_bug/demo.mjs:2:24
at ModuleJob.run (node:internal/modules/esm/module_job:413:25)
at async onImport.tracePromise.proto (node:internal/modules/esm/loader:660:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:101:5)

Node.js v24.12.0


### Possible Fix

this code has appeared in `@marko/compiler/dist/babel.js`

```ts
	var _browserslist = (() => {
		try {
			return require("browserslist");
		} catch {}
	})();

and surely enough if you add browserslist to your project it'll work.

Your Environment

a custom insane setup where i invoke the marko compiler myself

Steps to Reproduce

  1. first...

Stack Trace

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:unverified bugA bug report that has not been verified

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions