{"id":15506175,"url":"https://github.com/sooniter/circular-reference-rspack","last_synced_at":"2026-06-08T00:32:06.828Z","repository":{"id":250645785,"uuid":"835037091","full_name":"SoonIter/circular-reference-rspack","owner":"SoonIter","description":"`ReferenceError: Cannot access '__WEBPACK_DEFAULT_EXPORT__' before initialization`  circular import demo in esm with rspack/webpack  ","archived":false,"fork":false,"pushed_at":"2024-07-29T07:15:08.000Z","size":38,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-28T17:05:27.992Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SoonIter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-29T03:11:01.000Z","updated_at":"2024-07-29T07:15:12.000Z","dependencies_parsed_at":"2024-07-29T08:16:34.362Z","dependency_job_id":"c3b374eb-4064-424c-82b0-ef3019b3cc44","html_url":"https://github.com/SoonIter/circular-reference-rspack","commit_stats":null,"previous_names":["sooniter/circular-esm","sooniter/circular-reference-rspack"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoonIter%2Fcircular-reference-rspack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoonIter%2Fcircular-reference-rspack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoonIter%2Fcircular-reference-rspack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoonIter%2Fcircular-reference-rspack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SoonIter","download_url":"https://codeload.github.com/SoonIter/circular-reference-rspack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241596622,"owners_count":19988106,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T09:26:09.442Z","updated_at":"2025-11-29T01:13:17.551Z","avatar_url":"https://github.com/SoonIter.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Circular reference\n\n## Summary\n\n`output.environment.const = false` and `ReferenceError: Cannot access '__WEBPACK_DEFAULT_EXPORT__' before initialization`\n\nThis configuration will hide some potential runtime errors in the case of circular references.\n\nWe should try our best to use `output.environment.const = true` and repair circular references at development, `output.environment.const = false` can be used in an emergency.\n\n`output.environment.const = false` may be set under production due to browser compatibility of `const` syntax, so this error message might only show under development.\n\n```sh\n# dep graph\nindex.mjs -\u003e a.mjs \u003c-\u003e b.mjs\n```\n\nhttps://github.com/web-infra-dev/rsbuild/issues/2862\n\n```javascript\n// rspack.config.js\nmodule.exports = {\n  output: {\n    environment: {\n      const: false,\n    },\n  },\n};\n```\n\n## test\n\n### Node.js\n\n```sh\n❯ npm run run:esm\n\n\u003e circular-esm@ run:esm /Users/demos/circular-esm\n\u003e node ./src/index.mjs\n\nfile:///Users/demos/circular-esm/src/b.mjs:5\nconsole.log('a in b module', a);\n                             ^\n\nReferenceError: Cannot access 'a' before initialization\n    at file:///Users/demos/circular-esm/src/b.mjs:5:30\n    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)\n    at async Promise.all (index 0)\n    at async ESMLoader.import (node:internal/modules/esm/loader:530:24)\n    at async loadESM (node:internal/process/esm_loader:91:5)\n    at async handleMainPromise (node:internal/modules/run_main:65:12)\n```\n\n### Rspack/webpack\n\n#### `output.environment.const = false`\n\n```sh\n❯ npm run run\n\n\u003e circular-esm@ run /Users/demos/circular-esm\n\u003e rspack \u0026\u0026 node ./dist/main.js\n\nRspack compiled successfully in 66 ms\na in b module undefined\nb in a module modified-b\na in index.mjs undefined\n```\n\n#### `output.environment.const = true`\n\n```sh\n❯ npm run run\n\u003e circular-esm@ run /Users/demos/circular-esm\n\u003e rspack \u0026\u0026 node ./dist/main.js\n\nRspack compiled successfully in 11 ms\n/Users/demos/circular-esm/dist/main.js:6\n  Z: function() { return __WEBPACK_DEFAULT_EXPORT__; }\n                  ^\n\nReferenceError: Cannot access '__WEBPACK_DEFAULT_EXPORT__' before initialization\n    at Object.Z (/Users/demos/circular-esm/dist/main.js:6:19)\n    at Object../src/b.mjs (/Users/demos/circular-esm/dist/main.js:29:83)\n    at __webpack_require__ (/Users/demos/circular-esm/dist/main.js:55:30)\n    at Object../src/a.mjs (/Users/demos/circular-esm/dist/main.js:8:63)\n    at __webpack_require__ (/Users/demos/circular-esm/dist/main.js:55:30)\n    at /Users/demos/circular-esm/dist/main.js:94:63\n    at Object.\u003canonymous\u003e (/Users/demos/circular-esm/dist/main.js:100:3)\n    at Module._compile (node:internal/modules/cjs/loader:1165:14)\n    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1219:10)\n    at Module.load (node:internal/modules/cjs/loader:1043:32)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsooniter%2Fcircular-reference-rspack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsooniter%2Fcircular-reference-rspack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsooniter%2Fcircular-reference-rspack/lists"}