vite icon indicating copy to clipboard operation
vite copied to clipboard

RollupError: "node_modules/typescript/lib/typescript.js" contains dynamic require statements but it is not within the current dynamicRequireRoot "node_modules\typescript\lib". You should set dynamicRequireRoot to "node_modules/typescript/lib" or one of its parent directories.

Open mike-lischke opened this issue 2 years ago • 5 comments

Describe the bug

Recently I switched a web app project from CRA to vite and it's doing great. The last missing step to complete this task is to create a production build on Windows. And that gives me grief. Production builds on Linux + macOS go fine.

The build is triggered using a terminal script (production-build.cmd), which contains:

SET NODE_OPTIONS=--max-old-space-size=16000
node_modules/.bin/vite build

At some point I get the error message:

RollupError: "node_modules/typescript/lib/typescript.js" contains dynamic require statements but it is not within the current dynamicRequireRoot "node_modules\typescript\lib". You should set dynamicRequireRoot to "node_modules/typescript/lib" or one of its parent directories.

The instruction seems pretty clear, even though I wonder why this only comes up on Windows, not the other platforms. So I tried various combinations in vite.config.ts, like:

    build: {
        chunkSizeWarningLimit: 1000,
        commonjsOptions: {
            dynamicRequireTargets: [
                "node_modules/antlr4ts/**/*.js",
            ],
            dynamicRequireRoot: "node_modules/typescript",
        },

I also tried with wildcards and moving the folder to the dynamic require targets array. Nothing helped.

Reproduction

https://stackblitz.com/edit/vitejs-vite-tvxilx?file=index.html&terminal=dev

Steps to reproduce

npm run build

which in turn calls

call scripts/production-build.cmd

which executes:

SET NODE_OPTIONS=--max-old-space-size=16000
node_modules/.bin/vite build

System Info

System:
    OS: Windows 10 10.0.22000
    CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700T
    Memory: 31.24 GB / 47.70 GB
  Binaries:
    Node: 19.5.0 - C:\Program Files\nodejs\node.EXE
    npm: 9.3.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22000.120.0), Chromium (109.0.1518.61)
    Internet Explorer: 11.0.22000.120
  npmPackages:
    vite: 4.0.4 => 4.0.4

Used Package Manager

npm

Logs

Click to expand!
X:\work\develop\shell-plugins\gui\frontend>call antlr4ts -no-visitor -Xexact-output-dir -o src/parsing/mysql/generated src/parsing/mysql/*.g4
Generating file 'X:\work\develop\shell-plugins\gui\frontend\src\parsing\mysql\generated\MySQLLexer.interp' for grammar 'src\parsing\mysql\MySQLLexer.g4'
Generating file 'X:\work\develop\shell-plugins\gui\frontend\src\parsing\mysql\generated\MySQLLexer.ts' for grammar 'src\parsing\mysql\MySQLLexer.g4'
Generating file 'X:\work\develop\shell-plugins\gui\frontend\src\parsing\mysql\generated\MySQLLexer.tokens' for grammar 'src\parsing\mysql\MySQLLexer.g4'
Generating file 'X:\work\develop\shell-plugins\gui\frontend\src\parsing\mysql\generated\MySQLParser.interp' for grammar 'src\parsing\mysql\MySQLParser.g4'
Generating file 'X:\work\develop\shell-plugins\gui\frontend\src\parsing\mysql\generated\MySQLParser.ts' for grammar 'src\parsing\mysql\MySQLParser.g4'
Generating file 'X:\work\develop\shell-plugins\gui\frontend\src\parsing\mysql\generated\MySQLParserListener.ts' for grammar 'src\parsing\mysql\MySQLParser.g4'
Generating file 'X:\work\develop\shell-plugins\gui\frontend\src\parsing\mysql\generated\MySQLParser.tokens' for grammar 'src\parsing\mysql\MySQLParser.g4'
Generating file 'X:\work\develop\shell-plugins\gui\frontend\src\parsing\SQLite\generated\SQLiteLexer.interp' for grammar 'src\parsing\SQLite\SQLiteLexer.g4'
Generating file 'X:\work\develop\shell-plugins\gui\frontend\src\parsing\SQLite\generated\SQLiteLexer.ts' for grammar 'src\parsing\SQLite\SQLiteLexer.g4'
Generating file 'X:\work\develop\shell-plugins\gui\frontend\src\parsing\SQLite\generated\SQLiteLexer.tokens' for grammar 'src\parsing\SQLite\SQLiteLexer.g4'
Generating file 'X:\work\develop\shell-plugins\gui\frontend\src\parsing\SQLite\generated\SQLiteParser.interp' for grammar 'src\parsing\SQLite\SQLiteParser.g4'
Generating file 'X:\work\develop\shell-plugins\gui\frontend\src\parsing\SQLite\generated\SQLiteParser.ts' for grammar 'src\parsing\SQLite\SQLiteParser.g4'
Generating file 'X:\work\develop\shell-plugins\gui\frontend\src\parsing\SQLite\generated\SQLiteParserListener.ts' for grammar 'src\parsing\SQLite\SQLiteParser.g4'
Generating file 'X:\work\develop\shell-plugins\gui\frontend\src\parsing\SQLite\generated\SQLiteParser.tokens' for grammar 'src\parsing\SQLite\SQLiteParser.g4'
Generating file 'X:\work\develop\shell-plugins\gui\frontend\src\parsing\python\generated\PythonLexer.interp' for grammar 'src\parsing\python\PythonLexer.g4'
Generating file 'X:\work\develop\shell-plugins\gui\frontend\src\parsing\python\generated\PythonLexer.ts' for grammar 'src\parsing\python\PythonLexer.g4'
Generating file 'X:\work\develop\shell-plugins\gui\frontend\src\parsing\python\generated\PythonLexer.tokens' for grammar 'src\parsing\python\PythonLexer.g4'
Generating file 'X:\work\develop\shell-plugins\gui\frontend\src\parsing\python\generated\PythonParser.interp' for grammar 'src\parsing\python\PythonParser.g4'
Generating file 'X:\work\develop\shell-plugins\gui\frontend\src\parsing\python\generated\PythonParser.ts' for grammar 'src\parsing\python\PythonParser.g4'
Generating file 'X:\work\develop\shell-plugins\gui\frontend\src\parsing\python\generated\PythonParserListener.ts' for grammar 'src\parsing\python\PythonParser.g4'
Generating file 'X:\work\develop\shell-plugins\gui\frontend\src\parsing\python\generated\PythonParser.tokens' for grammar 'src\parsing\python\PythonParser.g4'
  vite:config bundled config file loaded in 284.84ms +0ms
  vite:esbuild init tsconfck (root: X:/work/develop/shell-plugins/gui/frontend) +0ms
  vite:esbuild init tsconfck (root: X:/work/develop/shell-plugins/gui/frontend) +2ms
  vite:esbuild init tsconfck (root: X:/work/develop/shell-plugins/gui/frontend) +0ms
  vite:esbuild init tsconfck (root: X:/work/develop/shell-plugins/gui/frontend) +1ms
  vite:esbuild init tsconfck end +30ms
  vite:esbuild init tsconfck end +0ms
  vite:esbuild init tsconfck end +1ms
  vite:esbuild init tsconfck end +0ms
  vite:config using resolved config: {
  vite:config   plugins: [
  vite:config     'vite:build-metadata',
  vite:config     'vite:pre-alias',
  vite:config     'alias',
  vite:config     'vite:preact-jsx',
  vite:config     'preact:devtools',
  vite:config     'vite:modulepreload-polyfill',
  vite:config     'vite:resolve',
  vite:config     'vite:html-inline-proxy',
  vite:config     'vite:css',
  vite:config     'vite:esbuild',
  vite:config     'vite:json',
  vite:config     'vite:wasm-helper',
  vite:config     'vite:worker',
  vite:config     'vite:asset',
  vite:config     'preact:config',
  vite:config     'prefresh',
  vite:config     'vite-plugin-moncao-editor',
  vite:config     'vite:wasm-fallback',
  vite:config     'vite:define',
  vite:config     'vite:css-post',
  vite:config     'vite:build-html',
  vite:config     'vite:worker-import-meta-url',
  vite:config     'vite:asset-import-meta-url',
  vite:config     'vite:force-systemjs-wrap-complete',
  vite:config     'vite:watch-package-data',
  vite:config     'commonjs',
  vite:config     'vite:data-uri',
  vite:config     'polyfill-node',
  vite:config     'commonjs',
  vite:config     'vite:dynamic-import-vars',
  vite:config     'vite:import-glob',
  vite:config     'vite:build-import-analysis',
  vite:config     'vite:esbuild-transpile',
  vite:config     'vite:terser',
  vite:config     'vite:reporter',
  vite:config     'vite:load-fallback'
  vite:config   ],
  vite:config   server: {
  vite:config     preTransformRequests: true,
  vite:config     host: '127.0.0.1',
  vite:config     port: 3001,
  vite:config     middlewareMode: false,
  vite:config     fs: { strict: true, allow: [Array], deny: [Array] }
  vite:config   },
  vite:config   define: {
  vite:config     'process.env': {
  vite:config       ALLUSERSPROFILE: 'C:\\ProgramData',
  vite:config       APPDATA: 'C:\\Users\\marcinm\\AppData\\Roaming',
  vite:config       COLOR: '1',
  vite:config       CommonProgramFiles: 'C:\\Program Files\\Common Files',
  vite:config       'CommonProgramFiles(x86)': 'C:\\Program Files (x86)\\Common Files',
  vite:config       CommonProgramW6432: 'C:\\Program Files\\Common Files',
  vite:config       COMPUTERNAME: 'MARCINM-DESKTOP',
  vite:config       ComSpec: 'C:\\Windows\\system32\\cmd.exe',
  vite:config       DEBUG: 'vite:*',
  vite:config       DriverData: 'C:\\Windows\\System32\\Drivers\\DriverData',
  vite:config       EDITOR: 'C:\\Windows\\notepad.exe',
  vite:config       FPS_BROWSER_APP_PROFILE_STRING: 'Internet Explorer',
  vite:config       FPS_BROWSER_USER_PROFILE_STRING: 'Default',
  vite:config       HOME: 'C:\\Users\\marcinm',
  vite:config       HOMEDRIVE: 'C:',
  vite:config       HOMEPATH: '\\Users\\marcinm',
  vite:config       INIT_CWD: 'X:\\work\\develop\\shell-plugins\\gui\\frontend',
  vite:config       LOCALAPPDATA: 'C:\\Users\\marcinm\\AppData\\Local',
  vite:config       LOGONSERVER: '\\\\MARCINM-DESKTOP',
  vite:config       NODE: 'C:\\Program Files\\nodejs\\node.exe',
  vite:config       NODE_ENV: 'production',
  vite:config       NODE_EXE: 'C:\\Program Files\\nodejs\\\\node.exe',
  vite:config       NODE_OPTIONS: '--max-old-space-size=16000',
  vite:config       NPM_CLI_JS: 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
  vite:config       npm_command: 'run-script',
  vite:config       npm_config_cache: 'C:\\Users\\marcinm\\AppData\\Local\\npm-cache',
  vite:config       npm_config_globalconfig: 'C:\\Program Files\\nodejs\\etc\\npmrc',
  vite:config       npm_config_global_prefix: 'C:\\Program Files\\nodejs',
  vite:config       npm_config_init_module: 'C:\\Users\\marcinm\\.npm-init.js',
  vite:config       npm_config_local_prefix: 'X:\\work\\develop\\shell-plugins\\gui\\frontend',
  vite:config       npm_config_metrics_registry: 'https://registry.npmjs.org/',
  vite:config       npm_config_node_gyp: 'D:\\tools\\nvm\\v19.5.0\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js',
  vite:config       npm_config_noproxy: '',
  vite:config       npm_config_prefix: 'C:\\Program Files\\nodejs',
  vite:config       npm_config_userconfig: 'C:\\Users\\marcinm\\.npmrc',
  vite:config       npm_config_user_agent: 'npm/9.3.1 node/v19.5.0 win32 x64 workspaces/false',
  vite:config       npm_execpath: 'D:\\tools\\nvm\\v19.5.0\\node_modules\\npm\\bin\\npm-cli.js',
  vite:config       npm_lifecycle_event: 'build-win',
  vite:config       npm_lifecycle_script: 'call ./scripts/production-build.cmd',
  vite:config       npm_node_execpath: 'C:\\Program Files\\nodejs\\node.exe',
  vite:config       npm_package_json: 'X:\\work\\develop\\shell-plugins\\gui\\frontend\\package.json',
  vite:config       npm_package_name: 'mysql-shell-gui',
  vite:config       npm_package_version: '1.6.1',
  vite:config       NPM_PREFIX_NPM_CLI_JS: 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
  vite:config       NUMBER_OF_PROCESSORS: '20',
  vite:config       NVM_HOME: 'D:\\tools\\nvm',
  vite:config       NVM_SYMLINK: 'C:\\Program Files\\nodejs',
  vite:config       OneDrive: 'C:\\Users\\marcinm\\OneDrive',
  vite:config       OS: 'Windows_NT',
  vite:config       Path: 'X:\\work\\develop\\shell-plugins\\gui\\frontend\\node_modules\\.bin;X:\\work\\develop\\shell-plugins\\gui\\node_modules\\.bin;X:\\work\\develop\\shell-plugins\\node_modules\\.bin;X:\\work\\develop\\node_modules\\.bin;X:\\work\\node_modules\\.bin;X:\\node_modules\\.bin;D:\\tools\\nvm\\v19.5.0\\node_modules\\npm\\node_modules\\@npmcli\\run-script\\lib\\node-gyp-bin;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\Program Files (x86)\\VMware\\VMware Workstation\\bin\\;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Program Files\\dotnet\\;C:\\Program Files\\Microsoft VS Code\\bin;C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\170\\Tools\\Binn\\;C:\\Program Files\\Microsoft SQL Server\\150\\Tools\\Binn\\;C:\\Program Files\\PuTTY\\;C:\\Program Files\\Docker\\Docker\\resources\\bin;C:\\Program Files\\Microsoft SQL Server\\120\\Tools\\Binn\\;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;D:\\tools\\nvm;C:\\Program Files\\nodejs;C:\\Program Files\\Git\\cmd;C:\\Python310\\Scripts\\;C:\\Python310\\;C:\\Users\\marcinm\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\marcinm\\.dotnet\\tools;d:\\tools\\swigwin-4.1.1\\;D:\\mysql\\mysql-shell-8.0.31\\bin;D:\\tools\\nvm;C:\\Program Files\\nodejs',
  vite:config       PATHEXT: '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC',
  vite:config       PROCESSOR_ARCHITECTURE: 'AMD64',
  vite:config       PROCESSOR_IDENTIFIER: 'Intel64 Family 6 Model 151 Stepping 2, GenuineIntel',
  vite:config       PROCESSOR_LEVEL: '6',
  vite:config       PROCESSOR_REVISION: '9702',
  vite:config       ProgramData: 'C:\\ProgramData',
  vite:config       ProgramFiles: 'C:\\Program Files',
  vite:config       'ProgramFiles(x86)': 'C:\\Program Files (x86)',
  vite:config       ProgramW6432: 'C:\\Program Files',
  vite:config       PROMPT: '$P$G',
  vite:config       PSModulePath: 'C:\\Program Files\\WindowsPowerShell\\Modules;C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules',
  vite:config       PUBLIC: 'C:\\Users\\Public',
  vite:config       SystemDrive: 'C:',
  vite:config       SystemRoot: 'C:\\Windows',
  vite:config       TEMP: 'C:\\Users\\marcinm\\AppData\\Local\\Temp',
  vite:config       TMP: 'C:\\Users\\marcinm\\AppData\\Local\\Temp',
  vite:config       USERDOMAIN: 'MARCINM-DESKTOP',
  vite:config       USERDOMAIN_ROAMINGPROFILE: 'MARCINM-DESKTOP',
  vite:config       USERNAME: 'marcinm',
  vite:config       USERPROFILE: 'C:\\Users\\marcinm',
  vite:config       VBOX_MSI_INSTALL_PATH: 'C:\\Program Files\\Oracle\\VirtualBox\\',
  vite:config       WB_3DPARTY_PATH: 'X:\\work\\develop\\workbench\\bundle',
  vite:config       windir: 'C:\\Windows',
  vite:config       WSLENV: 'WT_SESSION::WT_PROFILE_ID',
  vite:config       WT_PROFILE_ID: '{0caa0dad-35be-5f56-a8ff-afceeeaa6101}',
  vite:config       WT_SESSION: 'ed7d8f30-bf8d-4281-ab67-c5415fc3aa53',
  vite:config       ZES_ENABLE_SYSMAN: '1',
  vite:config       __PSLockDownPolicy: '0'
  vite:config     },
  vite:config     'process.env.buildNumber': '"7d299f2"',
  vite:config     'process.env.versionNumber': '"1.6.1"'
  vite:config   },
  vite:config   resolve: {
  vite:config     mainFields: [ 'module', 'jsnext:main', 'jsnext' ],
  vite:config     browserField: true,
  vite:config     conditions: [],
  vite:config     extensions: [
  vite:config       '.mjs',  '.js',
  vite:config       '.mts',  '.ts',
  vite:config       '.jsx',  '.tsx',
  vite:config       '.json'
  vite:config     ],
  vite:config     dedupe: [],
  vite:config     preserveSymlinks: false,
  vite:config     alias: [
  vite:config       [Object], [Object],
  vite:config       [Object], [Object],
  vite:config       [Object], [Object],
  vite:config       [Object], [Object],
  vite:config       [Object]
  vite:config     ]
  vite:config   },
  vite:config   optimizeDeps: {
  vite:config     disabled: 'build',
  vite:config     esbuildOptions: { preserveSymlinks: false, plugins: [Array], define: [Object] },
  vite:config     include: [
  vite:config       'preact/jsx-runtime',
  vite:config       'preact/jsx-dev-runtime',
  vite:config       'preact/debug',
  vite:config       'preact/devtools'
  vite:config     ]
  vite:config   },
  vite:config   build: {
  vite:config     target: [ 'es2020', 'edge88', 'firefox78', 'chrome87', 'safari14' ],
  vite:config     cssTarget: [ 'es2020', 'edge88', 'firefox78', 'chrome87', 'safari14' ],
  vite:config     outDir: 'dist',
  vite:config     assetsDir: 'assets',
  vite:config     assetsInlineLimit: 4096,
  vite:config     cssCodeSplit: true,
  vite:config     sourcemap: false,
  vite:config     rollupOptions: {
  vite:config       plugins: [Array],
  vite:config       output: [Object],
  vite:config       onwarn: [Function: onwarn],
  vite:config       shimMissingExports: true
  vite:config     },
  vite:config     minify: 'esbuild',
  vite:config     terserOptions: {},
  vite:config     write: true,
  vite:config     emptyOutDir: null,
  vite:config     copyPublicDir: true,
  vite:config     manifest: false,
  vite:config     lib: false,
  vite:config     ssr: false,
  vite:config     ssrManifest: false,
  vite:config     reportCompressedSize: true,
  vite:config     chunkSizeWarningLimit: 1000,
  vite:config     watch: null,
  vite:config     commonjsOptions: {
  vite:config       include: [Array],
  vite:config       extensions: [Array],
  vite:config       dynamicRequireTargets: [Array]
  vite:config     },
  vite:config     dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] },
  vite:config     modulePreload: { polyfill: true }
  vite:config   },
  vite:config   worker: {
  vite:config     format: 'es',
  vite:config     plugins: [
  vite:config       'vite:build-metadata',
  vite:config       'vite:pre-alias',
  vite:config       'alias',
  vite:config       'vite:modulepreload-polyfill',
  vite:config       'vite:resolve',
  vite:config       'vite:html-inline-proxy',
  vite:config       'vite:css',
  vite:config       'vite:esbuild',
  vite:config       'vite:json',
  vite:config       'vite:wasm-helper',
  vite:config       'vite:worker',
  vite:config       'vite:asset',
  vite:config       'vite:wasm-fallback',
  vite:config       'vite:define',
  vite:config       'vite:css-post',
  vite:config       'vite:build-html',
  vite:config       'vite:worker-import-meta-url',
  vite:config       'vite:asset-import-meta-url',
  vite:config       'vite:force-systemjs-wrap-complete',
  vite:config       'vite:watch-package-data',
  vite:config       'commonjs',
  vite:config       'vite:data-uri',
  vite:config       'polyfill-node',
  vite:config       'commonjs',
  vite:config       'vite:dynamic-import-vars',
  vite:config       'vite:import-glob',
  vite:config       'vite:build-import-analysis',
  vite:config       'vite:esbuild-transpile',
  vite:config       'vite:terser',
  vite:config       'vite:load-fallback'
  vite:config     ],
  vite:config     rollupOptions: {},
  vite:config     getSortedPlugins: [Function: getSortedPlugins],
  vite:config     getSortedPluginHooks: [Function: getSortedPluginHooks]
  vite:config   },
  vite:config   css: { devSourcemap: false },
  vite:config   configFile: 'X:/work/develop/shell-plugins/gui/frontend/vite.config.ts',
  vite:config   configFileDependencies: [
  vite:config     'X:/work/develop/shell-plugins/gui/frontend/package.json',
  vite:config     'X:/work/develop/shell-plugins/gui/frontend/vite.config.ts'
  vite:config   ],
  vite:config   inlineConfig: {
  vite:config     root: undefined,
  vite:config     base: undefined,
  vite:config     mode: undefined,
  vite:config     configFile: undefined,
  vite:config     logLevel: undefined,
  vite:config     clearScreen: undefined,
  vite:config     optimizeDeps: { force: undefined },
  vite:config     build: {}
  vite:config   },
  vite:config   root: 'X:/work/develop/shell-plugins/gui/frontend',
  vite:config   base: '/',
  vite:config   rawBase: '/',
  vite:config   publicDir: 'X:\\work\\develop\\shell-plugins\\gui\\frontend\\public',
  vite:config   cacheDir: 'X:/work/develop/shell-plugins/gui/frontend/node_modules/.vite',
  vite:config   command: 'build',
  vite:config   mode: 'production',
  vite:config   ssr: {
  vite:config     format: 'esm',
  vite:config     target: 'node',
  vite:config     optimizeDeps: { disabled: true, esbuildOptions: [Object] }
  vite:config   },
  vite:config   isWorker: false,
  vite:config   mainConfig: null,
  vite:config   isProduction: true,
  vite:config   preview: {
  vite:config     port: undefined,
  vite:config     strictPort: undefined,
  vite:config     host: '127.0.0.1',
  vite:config     https: undefined,
  vite:config     open: undefined,
  vite:config     proxy: undefined,
  vite:config     cors: undefined,
  vite:config     headers: undefined
  vite:config   },
  vite:config   env: { BASE_URL: '/', MODE: 'production', DEV: false, PROD: true },
  vite:config   assetsInclude: [Function: assetsInclude],
  vite:config   logger: {
  vite:config     hasWarned: false,
  vite:config     info: [Function: info],
  vite:config     warn: [Function: warn],
  vite:config     warnOnce: [Function: warnOnce],
  vite:config     error: [Function: error],
  vite:config     clearScreen: [Function: clearScreen],
  vite:config     hasErrorLogged: [Function: hasErrorLogged]
  vite:config   },
  vite:config   packageCache: Map(0) { set: [Function (anonymous)] },
  vite:config   createResolver: [Function: createResolver],
  vite:config   appType: 'spa',
  vite:config   experimental: { importGlobRestoreExtension: false, hmrPartialAccept: false },
  vite:config   getSortedPlugins: [Function: getSortedPlugins],
  vite:config   getSortedPluginHooks: [Function: getSortedPluginHooks]
  vite:config } +108ms
vite v4.0.4 building for production...
transforming (106) src\modules\db-editor\DBConnectionTab.tsx  vite:resolve 0.53ms ../assets/fonts/MySQL.ttf -> X:/work/develop/shell-plugins/gui/frontend/src/assets/fonts/MySQL.ttf +0ms
transforming (182) src\components\ui\Divider\Divider.css  vite:resolve 3.10ms ./checkerboard.png -> X:/work/develop/shell-plugins/gui/frontend/src/components/ui/ColorPicker/assets/checkerboard.png +691ms
  vite:resolve 2.98ms ./conic-gradient.png -> X:/work/develop/shell-plugins/gui/frontend/src/components/ui/ColorPicker/assets/conic-gradient.png +1ms
transforming (209) src\assets\images\schemaRoutine.svg  vite:resolve 1.31ms ../../../assets/images/squiggle.svg -> X:/work/develop/shell-plugins/gui/frontend/src/assets/images/squiggle.svg +371ms
  vite:resolve 1.47ms ../../../assets/images/editor-side-line.svg -> X:/work/develop/shell-plugins/gui/frontend/src/assets/images/editor-side-line.svg +0ms
✓ 298 modules transformed.
[commonjs--resolver] "X:/work/develop/shell-plugins/gui/frontend/node_modules/typescript/lib/typescript.js" contains dynamic require statements but it is not within the current dynamicRequireRoot "X:\work\develop\shell-plugins\gui\frontend". You should set dynamicRequireRoot to "X:/work/develop/shell-plugins/gui/frontend/node_modules/typescript/lib" or one of its parent directories.
file: X:/work/develop/shell-plugins/gui/frontend/node_modules/typescript/lib/typescript.js:3959:50
3957:          * @param separateBeginAndEnd - used for special cases where we need the trace point even if the event
3958:          * never terminates (typically for reducing a scenario too big to trace to one that can be completed).
3959:          * In the future we might implement an exit handler to dump unfinished events which would deprecate
                                                        ^
3960:          * these operations.
3961:          */
error during build:
RollupError: "X:/work/develop/shell-plugins/gui/frontend/node_modules/typescript/lib/typescript.js" contains dynamic require statements but it is not within the current dynamicRequireRoot "X:\work\develop\shell-plugins\gui\frontend". You should set dynamicRequireRoot to "X:/work/develop/shell-plugins/gui/frontend/node_modules/typescript/lib" or one of its parent directories.
    at error (file:///X:/work/develop/shell-plugins/gui/frontend/node_modules/rollup/dist/es/shared/rollup.js:2079:30)
    at Object.error (file:///X:/work/develop/shell-plugins/gui/frontend/node_modules/rollup/dist/es/shared/rollup.js:23564:20)
    at Object.error (file:///X:/work/develop/shell-plugins/gui/frontend/node_modules/rollup/dist/es/shared/rollup.js:22805:42)
    at checkDynamicRequire (file:///X:/work/develop/shell-plugins/gui/frontend/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:9482:14)
    at Object.enter (file:///X:/work/develop/shell-plugins/gui/frontend/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:9031:15)
    at SyncWalker.visit (file:///X:/work/develop/shell-plugins/gui/frontend/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:337:16)
    at SyncWalker.visit (file:///X:/work/develop/shell-plugins/gui/frontend/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:374:11)
    at SyncWalker.visit (file:///X:/work/develop/shell-plugins/gui/frontend/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:374:11)
    at SyncWalker.visit (file:///X:/work/develop/shell-plugins/gui/frontend/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:367:18)
    at SyncWalker.visit (file:///X:/work/develop/shell-plugins/gui/frontend/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:374:11)
    at SyncWalker.visit (file:///X:/work/develop/shell-plugins/gui/frontend/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:367:18)
    at SyncWalker.visit (file:///X:/work/develop/shell-plugins/gui/frontend/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:374:11)
    at SyncWalker.visit (file:///X:/work/develop/shell-plugins/gui/frontend/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:374:11)
    at SyncWalker.visit (file:///X:/work/develop/shell-plugins/gui/frontend/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:374:11)
    at SyncWalker.visit (file:///X:/work/develop/shell-plugins/gui/frontend/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:367:18)
    at walk$3 (file:///X:/work/develop/shell-plugins/gui/frontend/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:425:18)
    at transformCommonjs (file:///X:/work/develop/shell-plugins/gui/frontend/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:8905:3)
    at Object.transformAndCheckExports (file:///X:/work/develop/shell-plugins/gui/frontend/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:9496:12)
    at Object.transform (file:///X:/work/develop/shell-plugins/gui/frontend/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:9649:41)
    at file:///X:/work/develop/shell-plugins/gui/frontend/node_modules/rollup/dist/es/shared/rollup.js:23766:40

Validations

mike-lischke avatar Jan 27 '23 10:01 mike-lischke

The error also means that you're bundling typescript the library into the browser bundle. Is that correct? The repro doesn't show the issue either, it seems to be the default Vite template.

bluwy avatar Jan 27 '23 16:01 bluwy

Hello @mike-lischke. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction will be closed if they have no activity within 3 days.

github-actions[bot] avatar Jan 27 '23 16:01 github-actions[bot]

@bluwy Thanks for looking into this problem. Yes, Typescript is bundled with the application for online scripting support.

The app where we see that issue is pretty big and it took me days to configure it. Creating a minimal reproducible example is likely to consume another set of days, or at least several hours. I hoped the error message and the other info would be enough for a rough idea what could be wrong. Often, just pointing in the right direction is enough find a solution.

mike-lischke avatar Jan 27 '23 17:01 mike-lischke

Thanks @bluwy for keeping this issue open. In the next weeks we will likely be able to publish this setup of our application (currently it still is based on CRA). With that it should be easy for you to reproduce the issue.

mike-lischke avatar Jan 31 '23 07:01 mike-lischke

Sorry I've been meaning to take a look and give a suggestion, but haven't got around yet.

bluwy avatar Feb 04 '23 03:02 bluwy

RollupError: "node_modules/typescript/lib/typescript.js" contains dynamic require statements but it is not within the current dynamicRequireRoot "node_modules\typescript\lib". You should set dynamicRequireRoot to "node_modules/typescript/lib" or one of its parent directories.

It seems like there's a difference in the slashes here: node_modules\typescript\lib and node_modules/typescript/lib.

Maybe you can try this configuration?

import path from 'path'

// ...

dynamicRequireRoot: path.resolve(process.cwd(), './node_modules/typescript')

bluwy avatar Feb 06 '23 07:02 bluwy

I tried that and it had no effect at all. Even tried to use back slashes instead of the forward slashes. Is it possible to print the config to rollup, so we can see if the dynamic root is actually passed on?

mike-lischke avatar Feb 06 '23 13:02 mike-lischke

The option is handled by the Rollup plugin internally. Maybe you could insert a breakpoint before where the error occurred to see how that value is derived. And how the slash mismatch happens.

bluwy avatar Feb 07 '23 20:02 bluwy

What I wonder about is why the dynamicRequireRoot setting is part of the build->commonJsOptions? Shouldn't that setting be in the rollup section? And why do I even need commonJsOptions when I set the build output to ESM? I added my full configuration file to the question above. Maybe you can spot a problem there?

mike-lischke avatar Feb 08 '23 08:02 mike-lischke

After some more digging I found the problem, which is actually the opposite what the error says. So misleading...

The problem was that I (for some reasons I don't remember) added

            dynamicRequireTargets: [
                "node_modules/antlr4ts/**/*.js",
            ],

Removing it made the build succeed. So we see, not only too few, but also too many settings can break things. Thanks for listening! :-)

mike-lischke avatar Feb 08 '23 10:02 mike-lischke