Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sass not working with node 21 #14691

Closed
7 tasks done
brc-dd opened this issue Oct 19, 2023 · 4 comments
Closed
7 tasks done

sass not working with node 21 #14691

brc-dd opened this issue Oct 19, 2023 · 4 comments

Comments

@brc-dd
Copy link
Contributor

brc-dd commented Oct 19, 2023

Describe the bug

Using sass on node 21 is throwing errors.

Reproduction

https://github.com/brc-dd/vite-sass-bug

Steps to reproduce

Run pnpm install followed by pnpm dev. Issue seems to arise from the fact that typeof navigator is object on node 21. So probably a sass bug instead? 👀

System Info

System:
    OS: macOS 13.6
    CPU: (10) arm64 Apple M2 Pro
    Memory: 117.36 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.0.0 - ~/.nvm/versions/node/v21.0.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v21.0.0/bin/yarn
    npm: 10.2.0 - ~/.nvm/versions/node/v21.0.0/bin/npm
    pnpm: 8.9.2 - ~/.nvm/versions/node/v21.0.0/bin/pnpm
  Browsers:
    Safari: 17.0
    Safari Technology Preview: 17.4
  npmPackages:
    @vitejs/plugin-vue: ^4.2.3 => 4.4.0 
    vite: ^4.4.5 => 4.5.0

Used Package Manager

pnpm

Logs

Click to expand!
  vite:config bundled config file loaded in 147.21ms +0ms
  vite:config using resolved config: {
  vite:config   plugins: [
  vite:config     'vite:build-metadata',
  vite:config     'vite:watch-package-data',
  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:vue',
  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     'commonjs',
  vite:config     'vite:data-uri',
  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   optimizeDeps: {
  vite:config     disabled: 'build',
  vite:config     force: undefined,
  vite:config     esbuildOptions: { preserveSymlinks: false }
  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     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     ssrEmitAssets: false,
  vite:config     reportCompressedSize: true,
  vite:config     chunkSizeWarningLimit: 500,
  vite:config     watch: null,
  vite:config     commonjsOptions: { include: [Array], extensions: [Array] },
  vite:config     dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] },
  vite:config     modulePreload: { polyfill: true },
  vite:config     cssMinify: true
  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: [ 'vue' ],
  vite:config     preserveSymlinks: false,
  vite:config     alias: [ [Object], [Object] ]
  vite:config   },
  vite:config   define: { __VUE_OPTIONS_API__: true, __VUE_PROD_DEVTOOLS__: false },
  vite:config   ssr: {
  vite:config     format: 'esm',
  vite:config     target: 'node',
  vite:config     external: [],
  vite:config     optimizeDeps: { disabled: true, esbuildOptions: [Object] }
  vite:config   },
  vite:config   configFile: '/Users/divyansh/vite-project/vite.config.ts',
  vite:config   configFileDependencies: [ '/Users/divyansh/vite-project/vite.config.ts' ],
  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: '/Users/divyansh/vite-project',
  vite:config   base: '/',
  vite:config   rawBase: '/',
  vite:config   publicDir: '/Users/divyansh/vite-project/public',
  vite:config   cacheDir: '/Users/divyansh/vite-project/node_modules/.vite',
  vite:config   command: 'build',
  vite:config   mode: 'production',
  vite:config   isWorker: false,
  vite:config   mainConfig: null,
  vite:config   isProduction: true,
  vite:config   css: undefined,
  vite:config   esbuild: { jsxDev: false },
  vite:config   server: {
  vite:config     preTransformRequests: true,
  vite:config     sourcemapIgnoreList: [Function: isInNodeModules],
  vite:config     middlewareMode: false,
  vite:config     fs: { strict: true, allow: [Array], deny: [Array] }
  vite:config   },
  vite:config   preview: {
  vite:config     port: undefined,
  vite:config     strictPort: undefined,
  vite:config     host: undefined,
  vite:config     https: undefined,
  vite:config     open: undefined,
  vite:config     proxy: undefined,
  vite:config     cors: undefined,
  vite:config     headers: undefined
  vite:config   },
  vite:config   envDir: '/Users/divyansh/vite-project',
  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(1) {
  vite:config     'fnpd_/Users/divyansh/vite-project' => {
  vite:config       dir: '/Users/divyansh/vite-project',
  vite:config       data: [Object],
  vite:config       hasSideEffects: [Function: hasSideEffects],
  vite:config       webResolvedImports: {},
  vite:config       nodeResolvedImports: {},
  vite:config       setResolvedCache: [Function: setResolvedCache],
  vite:config       getResolvedCache: [Function: getResolvedCache]
  vite:config     },
  vite:config     set: [Function (anonymous)]
  vite:config   },
  vite:config   createResolver: [Function: createResolver],
  vite:config   worker: {
  vite:config     format: 'iife',
  vite:config     plugins: [
  vite:config       'vite:build-metadata',
  vite:config       'vite:watch-package-data',
  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       'commonjs',
  vite:config       'vite:data-uri',
  vite:config       'vite:worker-post',
  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   appType: 'spa',
  vite:config   experimental: { importGlobRestoreExtension: false, hmrPartialAccept: false },
  vite:config   getSortedPlugins: [Function: getSortedPlugins],
  vite:config   getSortedPluginHooks: [Function: getSortedPluginHooks]
  vite:config } +23ms
vite v4.5.0 building for production...
  vite:esbuild 128.10ms tsconfck init /Users/divyansh/vite-project +0ms
✓ 3 modules transformed.
✓ built in 233ms
[vite:css] Preprocessor dependency "sass" failed to load:
Cannot read properties of undefined (reading 'indexOf')
file: /Users/divyansh/vite-project/src/style.scss
error during build:
TypeError: Cannot read properties of undefined (reading 'indexOf')
    at /Users/divyansh/vite-project/node_modules/.pnpm/sass@1.69.4/node_modules/sass/sass.dart.js:116832:12
    at Object.applyHooksTransformer (/Users/divyansh/vite-project/node_modules/.pnpm/sass@1.69.4/node_modules/sass/sass.dart.js:1863:14)
    at Object.initHooks (/Users/divyansh/vite-project/node_modules/.pnpm/sass@1.69.4/node_modules/sass/sass.dart.js:1843:251)
    at Object.initNativeDispatchContinue (/Users/divyansh/vite-project/node_modules/.pnpm/sass@1.69.4/node_modules/sass/sass.dart.js:1809:9)
    at Object.initNativeDispatch (/Users/divyansh/vite-project/node_modules/.pnpm/sass@1.69.4/node_modules/sass/sass.dart.js:1803:9)
    at Object.getNativeInterceptor (/Users/divyansh/vite-project/node_modules/.pnpm/sass@1.69.4/node_modules/sass/sass.dart.js:29308:13)
    at Object.getInterceptor$x (/Users/divyansh/vite-project/node_modules/.pnpm/sass@1.69.4/node_modules/sass/sass.dart.js:29569:16)
    at Object.set$compile$x (/Users/divyansh/vite-project/node_modules/.pnpm/sass@1.69.4/node_modules/sass/sass.dart.js:29636:16)
    at Object.main (/Users/divyansh/vite-project/node_modules/.pnpm/sass@1.69.4/node_modules/sass/sass.dart.js:24401:9)
    at main2 (/Users/divyansh/vite-project/node_modules/.pnpm/sass@1.69.4/node_modules/sass/sass.dart.js:26210:9)
Error: Preprocessor dependency "sass" failed to load:
Cannot read properties of undefined (reading 'indexOf')
    at loadPreprocessor (file:///Users/divyansh/vite-project/node_modules/.pnpm/vite@4.5.0_sass@1.69.4/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:39307:29)
    at scss (file:///Users/divyansh/vite-project/node_modules/.pnpm/vite@4.5.0_sass@1.69.4/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:39345:20)
    at compileCSSPreprocessors (file:///Users/divyansh/vite-project/node_modules/.pnpm/vite@4.5.0_sass@1.69.4/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:38770:36)
    at compileCSS (file:///Users/divyansh/vite-project/node_modules/.pnpm/vite@4.5.0_sass@1.69.4/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:38820:42)
    at async Object.transform (file:///Users/divyansh/vite-project/node_modules/.pnpm/vite@4.5.0_sass@1.69.4/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:38300:56)
    at async transform (file:///Users/divyansh/vite-project/node_modules/.pnpm/rollup@3.29.4/node_modules/rollup/dist/es/shared/node-entry.js:24449:16)
    at async ModuleLoader.addModuleSource (file:///Users/divyansh/vite-project/node_modules/.pnpm/rollup@3.29.4/node_modules/rollup/dist/es/shared/node-entry.js:24649:30)
 ELIFECYCLE  Command failed with exit code 1.

Validations

@brc-dd
Copy link
Contributor Author

brc-dd commented Oct 19, 2023

Duplicate of dart-lang/sdk#53784

@brc-dd brc-dd closed this as not planned Won't fix, can't repro, duplicate, stale Oct 19, 2023
@mpr0xy
Copy link

mpr0xy commented Oct 26, 2023

Here is my temporary solution

In the vite.config.ts file, first write

if (!navigator.userAgent) {
  //@ts-ignore
  navigator.userAgent = "";
}

Can alleviate errors

@brc-dd
Copy link
Contributor Author

brc-dd commented Oct 26, 2023

I don't think that error would occur on node 16. navigator global was only added in node 21, and most likely not backported.

@mpr0xy
Copy link

mpr0xy commented Nov 3, 2023

I don't think that error would occur on node 16. navigator global was only added in node 21, and most likely not backported.

Yes, I confused the currently running node version.

Nodejs version 21 will cause errors.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants