{"record":{"id":"dc15eb74a4a0514d","repo":"grafana/k6","slug":"you-are-trying-to-access-identifier-q-this-likel","errorCode":null,"errorMessage":"you are trying to access identifier %q, this likely is due to mixing ECMAScript Modules (ESM) and CommonJS syntax. This isn't supported in the JavaScript standard, please use only one or the other","messagePattern":"you are trying to access identifier %q, this likely is due to mixing ECMAScript Modules \\(ESM\\) and CommonJS syntax\\. This isn't supported in the JavaScript standard, please use only one or the other","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/bundle.go","lineNumber":509,"sourceCode":"\t\t\tlogger := b.preInitState.Logger\n\t\t\tif shouldWarn {\n\t\t\t\tlogger.Warningf(\"open() was used and is currently relative to '%s', but in the future \"+\n\t\t\t\t\t\"it will be aligned with how `require` and imports work and will be relative to '%s'. This means \"+\n\t\t\t\t\t\"that in the future open will open relative path relative to the module/file it is written in. \"+\n\t\t\t\t\t\"You can future proof this by using `import.meta.resolve()` to get relative paths to the file it \"+\n\t\t\t\t\t\"is written in the current k6 version.\", pwd, otherPath)\n\t\t\t\terr = b.preInitState.Usage.Uint64(\"deprecations/openRelativity\", 1)\n\t\t\t\tif err != nil {\n\t\t\t\t\tlogger.WithError(err).Warn(\"failed reporting usage of deprecated relativity of open()\")\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn openImpl(rt, b.filesystems[\"file\"], pwd, filename, args...)\n\t})\n\twarnAboutModuleMixing := func(name string) {\n\t\twarnFunc := rt.ToValue(func() error {\n\t\t\treturn fmt.Errorf(\n\t\t\t\t\"you are trying to access identifier %q, this likely is due to mixing \"+\n\t\t\t\t\t\"ECMAScript Modules (ESM) and CommonJS syntax. \"+\n\t\t\t\t\t\"This isn't supported in the JavaScript standard, please use only one or the other\",\n\t\t\t\tname)\n\t\t})\n\t\terr := rt.GlobalObject().DefineAccessorProperty(name, warnFunc, warnFunc, sobek.FLAG_FALSE, sobek.FLAG_FALSE)\n\t\tif err != nil {\n\t\t\tpanic(fmt.Errorf(\"failed to set '%s' global object: %w\", name, err))\n\t\t}\n\t}\n\twarnAboutModuleMixing(\"module\")\n\twarnAboutModuleMixing(\"exports\")\n\n\trt.SetFinalImportMeta(func(o *sobek.Object, mr sobek.ModuleRecord) {\n\t\terr := o.Set(\"resolve\", func(specifier string) (string, error) {\n\t\t\tu, err := modSys.Resolve(mr, specifier)\n\t\t\tif err != nil {\n\t\t\t\treturn \"\", err","sourceCodeStart":491,"sourceCodeEnd":527,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/bundle.go#L491-L527","documentation":"To catch module-system mixing, setInitGlobals installs accessor traps (warnAboutModuleMixing) on the `module` and `exports` globals. Reading or writing either identifier in a script invokes a function that returns this error, because a file cannot legitimately be both an ES module (import/export) and CommonJS (require/module.exports) - the ECMAScript standard forbids it and k6's ESM transform would otherwise misbehave silently.","triggerScenarios":"A script that uses import/export and also references `module` or `exports`: `module.exports = {...}` copied from CommonJS, `exports.default = ...` left over from a Babel/Jest template, or destructuring from `module`.","commonSituations":"Copy-pasting Node/Jest/Mocha snippets into k6 scripts; converting an old CommonJS k6 script to ESM halfway through; bundler output that references `exports`.","solutions":["Pick one module system per file: in a file that uses import/export, remove every `module`/`exports` reference","Replace `module.exports = { x }` with `export const x` or `export default`","Replace require() with import in the same file, since the mixed variants break resolution too"],"exampleFix":"// before: ESM import plus CommonJS export -> trap fires\nimport http from 'k6/http';\nmodule.exports = { doThing: () => http.get('https://k6.io') };\n\n// after: single module system (ESM)\nimport http from 'k6/http';\nexport const doThing = () => http.get('https://k6.io');","handlingStrategy":"validation","validationCode":"# flag files that mix module systems: ESM syntax AND module/exports references\nfor f in *.js; do\n  grep -qE '^[[:space:]]*(import|export)[[:space:]]' \"$f\" || continue\n  grep -qE '\\b(module|exports)\\b\\s*[.=]' \"$f\" && echo \"mixed module systems: $f\"\ndone","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Choose one module system per file and stick to it project-wide","When converting CommonJS to ESM, search the file for 'module' and 'exports' after removing require()","Be careful pasting Jest/Mocha snippets - they are CommonJS and often reference module.exports"],"tags":["esm","commonjs","modules","migration"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}