{"id":792,"hash":"6be897706c2e57a53f3371e6e40d4eefa72afdb49244901887a909a740ea1ff9","pattern":"Error: Illegal reassignment to import","full_message":"I am trying to import a module into a typescript file and then bundle with Rollup.js.\n\nBut I am getting an error message which prevents Rollup from completing. \n\nThe import:\n\nimport * as mapboxgl from 'mapbox-gl';\n\n(mapboxgl as any).accessToken = this.accessToken;\nthis.map = new mapbox.Map({...});\n\nWhen I run tsc there is not any error messages, but then when I run:\n\n$ rollup -c rollup.config.js\n\nIllegal reassignment to import 'mapboxgl'\nError: Illegal reassignment to import 'mapboxgl'\nat error (C:\\Users\\m.wilson\\AppData\\Roaming\\npm\\node_modules\\rollup\\src\\utils\\error.js:2:14)\nat disallowIllegalReassignment (C:\\Users\\m.wilson\\AppData\\Roaming\\npm\\node_modules\\rollup\\src\\ast\\nodes\\shared\\disallowIllegalReassignment.js:9:4)\nat Node.bind (C:\\Users\\m.wilson\\AppData\\Roaming\\npm\\node_modules\\rollup\\src\\ast\\nodes\\AssignmentExpression.js:12:3)\nat C:\\Users\\m.wilson\\AppData\\Roaming\\npm\\node_modules\\rollup\\src\\ast\\Node.js:6:34\nat Node.eachChild (C:\\Users\\m.wilson\\AppData\\Roaming\\npm\\node_modules\\rollup\\src\\ast\\Node.js:21:5)\nat Node.bind (C:\\Users\\m.wilson\\AppData\\Roaming\\npm\\node_modules\\rollup\\src\\ast\\Node.js:6:8)\nat Node.bind (C:\\Users\\m.wilson\\AppData\\Roaming\\npm\\node_modules\\rollup\\src\\ast\\nodes\\BlockStatement.js:8:9)\nat Node.bind (C:\\Users\\m.wilson\\AppData\\Roaming\\npm\\node_modules\\rollup\\src\\ast\\nodes\\FunctionExpression.js:7:13)\nat C:\\Users\\m.wilson\\AppData\\Roaming\\npm\\node_modules\\rollup\\src\\ast\\Node.js:6:34\nat Node.eachChild (C:\\Users\\m.wilson\\AppData\\Roaming\\npm\\node_modules\\rollup\\src\\ast\\Node.js:21:5)\nType rollup --help for help, or visit https://github.com/rollup/rollup/wiki\n\nI've narrowed down that the error only occurs when (mapboxgl as any).accessToken = this.accessToken; is present.\n\nMy rollup.config.js looks like this:\n\nexport default {\n  moduleName: \"mapbox.core\",\n  entry: 'src/js/index.js',\n  format: 'umd',\n  dest: 'core/core.umd.js',\n  sourceMap: true,\n  globals: {\n   'mapbox-gl': 'mapboxgl'\n  }\n};","ecosystem":"npm","package_name":"typescript","package_version":null,"solution":"Pretty annoying and not really sure why it has to be done this way, but I managed to avoid the error and still get the mapbox-gl module to work by using an assign function to set the accessToken on mapboxgl \n\nSo I changed:\n\nimport * as mapboxgl from 'mapbox-gl';\n\n(mapboxgl as any).accessToken = this.accessToken;\nthis.map = new mapbox.Map({...});\n\nTo this:\n\nimport * as mapboxgl from 'mapbox-gl';\n\nthis.assign(mapboxgl, \"accessToken\", this.accessToken);\nthis.map = new mapboxgl.Map({...});\n\n/*\n *\n * credit to this answer for the assign function:\n * http://stackoverflow.com/a/13719799/2393347\n *\n */\nprivate assign(obj: any, prop: any, value: any) {\n    if (typeof prop === \"string\")\n        prop = prop.split(\".\");\n\n    if (prop.length > 1) {\n        var e = prop.shift();\n        this.assign(obj[e] =\n                Object.prototype.toString.call(obj[e]) === \"[object Object]\"\n                ? obj[e]\n                : {},\n            prop,\n            value);\n    } else\n        obj[prop[0]] = value;\n}","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/41057604/error-illegal-reassignment-to-import","votes":9,"created_at":"2026-04-19T04:51:43.006956+00:00","updated_at":"2026-04-19T04:51:43.006956+00:00"}