TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for node_modules/@spotlightjs/astro/src/index.ts
Environment
What version are you running? Etc.
node v21.4.0 (npm v10.2.4)
Astro 4.0.3
yarn 4.0.2
Steps to Reproduce
- Use existing Astro project
yarn astro add @sentry/astro @spotlightjs/astroyarn run dev
Expected Result
Easy integration install, like in README.
Actual Result
Project cannot run/compile. spotlightjs() integration has to be removed from astro.config.mjs to make it work again.
tsconfig.json
{
"extends": "astro/tsconfigs/strict",
"include": ["src/**/*"],
"exclude": ["node_modules/*", "__sapper__/*", "public/*"],
"compilerOptions": {
"baseUrl": "/Users/manzark/Developer/DEV-065_New_Website_Astro3.0",
"paths": {
"@components/*": ["src/components/*"],
"@img/*": ["assets/img/*"]
},
"strictNullChecks": true,
"allowJs": true,
"jsx": "preserve",
"jsxImportSource": "solid-js"
}
}
Log:
DEBUG=astro:*,vite:* yarn run start
astro:telemetry [notify] last notified on 1694723646877 +0ms
astro:Failed to load config with Node TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /Users/manzark/Developer/DEV-065_New_Website_Astro3.0/node_modules/@spotlightjs/astro/src/index.ts
astro:Failed to load config with Node at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:160:9)
astro:Failed to load config with Node at defaultGetFormat (node:internal/modules/esm/get_format:203:36)
astro:Failed to load config with Node at defaultLoad (node:internal/modules/esm/load:143:22)
astro:Failed to load config with Node at async ModuleLoader.load (node:internal/modules/esm/loader:409:7)
astro:Failed to load config with Node at async ModuleLoader.moduleProvider (node:internal/modules/esm/loader:291:45) +0ms
vite:config bundled config file loaded in 779.35ms +0ms
vite:config using resolved config: {
vite:config esbuild: {
vite:config jsxDev: true,
vite:config loader: 'tsx',
vite:config include: /src\/components\/.*\.tsx$/,
vite:config exclude: [],
vite:config target: 'es2017'
vite:config },
vite:config server: {
vite:config preTransformRequests: true,
vite:config middlewareMode: true,
vite:config hmr: false,
vite:config watch: { ignored: [Array] },
vite:config sourcemapIgnoreList: [Function: isInNodeModules$1],
vite:config fs: { strict: true, allow: [Array], deny: [Array] }
vite:config },
vite:config optimizeDeps: { disabled: true, esbuildOptions: { preserveSymlinks: false } },
vite:config clearScreen: false,
vite:config appType: 'custom',
vite:config ssr: {
vite:config target: 'node',
vite:config external: [
vite:config '@astrojs/tailwind',
vite:config '@astrojs/mdx',
vite:config '@astrojs/react',
vite:config '@astrojs/preact',
vite:config '@astrojs/sitemap',
vite:config '@astrojs/markdoc'
vite:config ],
vite:config optimizeDeps: { disabled: true, esbuildOptions: [Object] }
vite:config },
vite:config plugins: [
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:worker-import-meta-url',
vite:config 'vite:asset-import-meta-url',
vite:config 'vite:dynamic-import-vars',
vite:config 'vite:import-glob',
vite:config 'vite:client-inject',
vite:config 'vite:import-analysis'
vite:config ],
vite:config configFile: '/Users/manzark/Developer/DEV-065_New_Website_Astro3.0/vite.config.js',
vite:config configFileDependencies: [
vite:config '/Users/manzark/Developer/DEV-065_New_Website_Astro3.0/vite.config.js'
vite:config ],
vite:config inlineConfig: {
vite:config server: { middlewareMode: true, hmr: false, watch: [Object] },
vite:config optimizeDeps: { disabled: true },
vite:config clearScreen: false,
vite:config appType: 'custom',
vite:config ssr: { external: [Array] },
vite:config plugins: [ false ]
vite:config },
vite:config root: '/Users/manzark/Developer/DEV-065_New_Website_Astro3.0',
vite:config base: '/',
vite:config rawBase: '/',
vite:config resolve: {
vite:config mainFields: [ 'browser', 'module', 'jsnext:main', 'jsnext' ],
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: [ [Object], [Object] ]
vite:config },
vite:config publicDir: '/Users/manzark/Developer/DEV-065_New_Website_Astro3.0/public',
vite:config cacheDir: '/Users/manzark/Developer/DEV-065_New_Website_Astro3.0/node_modules/.vite',
vite:config command: 'serve',
vite:config mode: 'development',
vite:config isWorker: false,
vite:config mainConfig: null,
vite:config isProduction: false,
vite:config css: { lightningcss: undefined },
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 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/manzark/Developer/DEV-065_New_Website_Astro3.0',
vite:config env: { BASE_URL: '/', MODE: 'development', DEV: true, PROD: false },
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/manzark/Developer/DEV-065_New_Website_Astro3.0' => {
vite:config dir: '/Users/manzark/Developer/DEV-065_New_Website_Astro3.0',
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: { format: 'iife', plugins: '() => plugins', rollupOptions: {} },
vite:config experimental: { importGlobRestoreExtension: false, hmrPartialAccept: false },
vite:config getSortedPlugins: [Function: getSortedPlugins],
vite:config getSortedPluginHooks: [Function: getSortedPluginHooks]
vite:config } +11ms
vite:load 17.37ms [fs] astro.config.mjs +0ms
vite:resolve 4.24ms @spotlightjs/astro -> /Users/manzark/Developer/DEV-065_New_Website_Astro3.0/node_modules/@spotlightjs/astro/src/index.ts +0ms
vite:resolve 1.19ms /node_modules/@spotlightjs/astro/src/index.ts -> /Users/manzark/Developer/DEV-065_New_Website_Astro3.0/node_modules/@spotlightjs/astro/src/index.ts +13ms
vite:import-analysis 34.37ms [1 imports rewritten] astro.config.mjs +0ms
vite:transform 38.79ms astro.config.mjs +0ms
vite:load 603.68ms [fs] /node_modules/@spotlightjs/astro/src/index.ts +645ms
vite:resolve 8.44ms ./snippets -> /Users/manzark/Developer/DEV-065_New_Website_Astro3.0/node_modules/@spotlightjs/astro/src/snippets.ts +626ms
vite:resolve 8.86ms ./types -> /Users/manzark/Developer/DEV-065_New_Website_Astro3.0/node_modules/@spotlightjs/astro/src/types.ts +1ms
vite:resolve 9.21ms ./vite/error-page -> /Users/manzark/Developer/DEV-065_New_Website_Astro3.0/node_modules/@spotlightjs/astro/src/vite/error-page.ts +0ms
vite:resolve 9.43ms ./vite/source-context -> /Users/manzark/Developer/DEV-065_New_Website_Astro3.0/node_modules/@spotlightjs/astro/src/vite/source-context.ts +0ms
vite:resolve 6.47ms /node_modules/@spotlightjs/astro/src/snippets.ts -> /Users/manzark/Developer/DEV-065_New_Website_Astro3.0/node_modules/@spotlightjs/astro/src/snippets.ts +7ms
vite:resolve 6.50ms /node_modules/@spotlightjs/astro/src/types.ts -> /Users/manzark/Developer/DEV-065_New_Website_Astro3.0/node_modules/@spotlightjs/astro/src/types.ts +0ms
vite:resolve 7.81ms /node_modules/@spotlightjs/astro/src/vite/error-page.ts -> /Users/manzark/Developer/DEV-065_New_Website_Astro3.0/node_modules/@spotlightjs/astro/src/vite/error-page.ts +2ms
vite:resolve 6.87ms /node_modules/@spotlightjs/astro/src/vite/source-context.ts -> /Users/manzark/Developer/DEV-065_New_Website_Astro3.0/node_modules/@spotlightjs/astro/src/vite/source-context.ts +0ms
vite:import-analysis 25.66ms [4 imports rewritten] node_modules/@spotlightjs/astro/src/index.ts +631ms
vite:transform 26.40ms /node_modules/@spotlightjs/astro/src/index.ts +630ms
2:28:45 AM [vite] Pre-transform error: Expected ',', got '{'
vite:load 51.02ms [fs] /node_modules/@spotlightjs/astro/src/vite/error-page.ts +78ms
vite:resolve 0.96ms ../snippets -> /Users/manzark/Developer/DEV-065_New_Website_Astro3.0/node_modules/@spotlightjs/astro/src/snippets.ts +70ms
vite:resolve 0.45ms ../types -> /Users/manzark/Developer/DEV-065_New_Website_Astro3.0/node_modules/@spotlightjs/astro/src/types.ts +0ms
vite:import-analysis 17.98ms [2 imports rewritten] node_modules/@spotlightjs/astro/src/vite/error-page.ts +70ms
vite:transform 18.55ms /node_modules/@spotlightjs/astro/src/vite/error-page.ts +70ms
vite:load 70.33ms [fs] /node_modules/@spotlightjs/astro/src/snippets.ts +20ms
vite:import-analysis 0.58ms [1 imports rewritten] node_modules/@spotlightjs/astro/src/snippets.ts +2ms
vite:transform 0.81ms /node_modules/@spotlightjs/astro/src/snippets.ts +2ms
vite:load 145.69ms [fs] /node_modules/@spotlightjs/astro/src/types.ts +75ms
vite:import-analysis 0.04ms [no imports] node_modules/@spotlightjs/astro/src/types.ts +78ms
vite:transform 0.41ms /node_modules/@spotlightjs/astro/src/types.ts +78ms
2:28:46 AM [vite] Pre-transform error: Expected ',', got '{'
2:28:46 AM [vite] Pre-transform error: Expected ',', got '{'
2:28:46 AM [vite] Pre-transform error: Expected ',', got '{'
2:28:46 AM [vite] Pre-transform error: Expected '{', got 'type'
2:28:46 AM [vite] Pre-transform error: Expected '{', got 'type'
2:28:46 AM [vite] Pre-transform error: Expected '{', got 'type'
vite:load 0.77ms [fs] /node_modules/@spotlightjs/astro/src/index.ts +1s
vite:import-analysis 1.70ms [4 imports rewritten] node_modules/@spotlightjs/astro/src/index.ts +1s
vite:transform 1.96ms /node_modules/@spotlightjs/astro/src/index.ts +1s
2:28:47 AM [vite] Error when evaluating SSR module /Users/manzark/Developer/DEV-065_New_Website_Astro3.0/astro.config.mjs: failed to import "/node_modules/@spotlightjs/astro/src/index.ts"
|- RollupError: Expected ',', got '{'
at error (file:///Users/manzark/Developer/DEV-065_New_Website_Astro3.0/node_modules/rollup/dist/es/shared/parseAst.js:337:30)
at nodeConverters (file:///Users/manzark/Developer/DEV-065_New_Website_Astro3.0/node_modules/rollup/dist/es/shared/parseAst.js:2084:9)
at convertNode (file:///Users/manzark/Developer/DEV-065_New_Website_Astro3.0/node_modules/rollup/dist/es/shared/parseAst.js:969:12)
at convertProgram (file:///Users/manzark/Developer/DEV-065_New_Website_Astro3.0/node_modules/rollup/dist/es/shared/parseAst.js:960:48)
at parseAstAsync (file:///Users/manzark/Developer/DEV-065_New_Website_Astro3.0/node_modules/rollup/dist/es/shared/parseAst.js:2150:20)
at async ssrTransformScript (file:///Users/manzark/Developer/DEV-065_New_Website_Astro3.0/node_modules/vite/dist/node/chunks/dep-YJaePtkC.js:49505:15)
at async loadAndTransform (file:///Users/manzark/Developer/DEV-065_New_Website_Astro3.0/node_modules/vite/dist/node/chunks/dep-YJaePtkC.js:49093:11)
at async instantiateModule (file:///Users/manzark/Developer/DEV-065_New_Website_Astro3.0/node_modules/vite/dist/node/chunks/dep-YJaePtkC.js:50063:10)
vite:load 10.31ms [fs] /node_modules/@spotlightjs/astro/src/types.ts +12ms
vite:import-analysis 0.03ms [no imports] node_modules/@spotlightjs/astro/src/types.ts +10ms
vite:transform 0.20ms /node_modules/@spotlightjs/astro/src/types.ts +11ms
vite:load 10.72ms [fs] /node_modules/@spotlightjs/astro/src/vite/error-page.ts +1ms
vite:import-analysis 0.82ms [2 imports rewritten] node_modules/@spotlightjs/astro/src/vite/error-page.ts +2ms
vite:transform 1.00ms /node_modules/@spotlightjs/astro/src/vite/error-page.ts +1ms
vite:load 11.92ms [fs] /node_modules/@spotlightjs/astro/src/snippets.ts +1ms
vite:import-analysis 0.50ms [1 imports rewritten] node_modules/@spotlightjs/astro/src/snippets.ts +1ms
vite:transform 1.36ms /node_modules/@spotlightjs/astro/src/snippets.ts +1ms
2:28:47 AM [vite] Pre-transform error: Expected '{', got 'type'
2:28:47 AM [vite] Pre-transform error: Expected '{', got 'type'
2:28:47 AM [vite] Pre-transform error: Expected '{', got 'type'
2:28:47 AM [vite] Pre-transform error: Expected ',', got '{'
2:28:47 AM [vite] Pre-transform error: Expected ',', got '{'
2:28:47 AM [vite] Pre-transform error: Expected ',', got '{'
[astro] Unable to load your Astro config
astro:telemetry {
astro:telemetry context: {
astro:telemetry isGit: true,
astro:telemetry anonymousProjectId: '689c4e00762a92061d9939cea1eccd79d83d9ca9d11f911cc5901db2904c2af5',
astro:telemetry packageManager: 'yarn',
astro:telemetry packageManagerVersion: '4.0.2',
astro:telemetry anonymousId: '63bbff689b1b37068244b736af1d309f1d70fbc4bb7d4d6813ce721c378f798a',
astro:telemetry anonymousSessionId: '522810b71b1655c92422c6b1f549307cade21f39c175b1b87f8346635ba2dd69'
astro:telemetry },
astro:telemetry meta: {
astro:telemetry nodeVersion: '21.4.0',
astro:telemetry viteVersion: '5.0.6',
astro:telemetry astroVersion: '4.0.3',
astro:telemetry systemPlatform: 'darwin',
astro:telemetry systemRelease: '21.6.0',
astro:telemetry systemArchitecture: 'x64',
astro:telemetry cpuCount: 4,
astro:telemetry cpuModel: 'Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz',
astro:telemetry cpuSpeed: 2400,
astro:telemetry memoryInMb: 8192,
astro:telemetry isDocker: false,
astro:telemetry isTTY: true,
astro:telemetry isWSL: false,
astro:telemetry isCI: false,
astro:telemetry ciName: null
astro:telemetry }
astro:telemetry } +5s
astro:telemetry [
astro:telemetry {
astro:telemetry "eventName": "ASTRO_CLI_ERROR",
astro:telemetry "payload": {
astro:telemetry "name": "RollupError",
astro:telemetry "cliCommand": "dev",
astro:telemetry "isFatal": true,
astro:telemetry "anonymousMessageHint": "Expected"
astro:telemetry }
astro:telemetry }
astro:telemetry ] +2ms
Expected ',', got '{'
Stack trace:
at error (file:///Users/manzark/Developer/DEV-065_New_Website_Astro3.0/node_modules/rollup/dist/es/shared/parseAst.js:337:30)
at convertNode (file:///Users/manzark/Developer/DEV-065_New_Website_Astro3.0/node_modules/rollup/dist/es/shared/parseAst.js:969:12)
at parseAstAsync (file:///Users/manzark/Developer/DEV-065_New_Website_Astro3.0/node_modules/rollup/dist/es/shared/parseAst.js:2150:20)
at async loadAndTransform (file:///Users/manzark/Developer/DEV-065_New_Website_Astro3.0/node_modules/vite/dist/node/chunks/dep-YJaePtkC.js:49093:11)
Hi @AdamAdamsMusic thanks for writing in! I'm a bit surprised about this error given that Astro integrations can be shipped as typescript in the NPM package. Can you share your vite.config.js file?
I'm not sure but maybe the "exclude": ["node_modules/*", "__sapper__/*", "public/*"] line in your tsconfig.json plays a role here.
I am as surprised as you are! First time this has happened to me, although I'm fairly new in Astro world, haha!
Of course, here's my vite.config.js:
export default {
esbuild: {
loader: 'tsx',
include: /src\/components\/.*\.ts.$/,
exclude: [],
target: 'es2017',
},
};
Tried without the "exclude": ["node_modules/*", "__sapper__/*", "public/*"] line in tsconfig.json – same thing happens.
@AdamAdamsMusic thanks! Any chance you could provide us a minimal reproduction where the error still occurs? It's very hard to debug this otherwise.
@Lms24 Absolutely! Here it is: https://github.com/AdamAdamsMusic/astro-spotlightjs-ts-issue
i am not sure but there is any issue with include and target defined in vite.config.js which is causing this issue.
Tried again and encountered this error. Created a separate issue (with a repro) but looks like a dupe of this one.
- https://github.com/getsentry/spotlight/issues/255
Ok, I found a solution. @Shubhdeep12 was on the right track.
My previous vite.config.js was this:
export default {
esbuild: {
loader: 'tsx',
include: /src\/components\/.*\.ts.$/,
exclude: [],
target: 'es2017',
},
moduleResolution: 'bundler',
};
I commented out the include option, and changed target to esnext and it started working. Hasn't broken anything else in my project (I think).
Please verify this @Lms24. Maybe it's worth adding to docs/readme that target: 'esnext' is the requirement for it to be compiled properly.
Hi @Lms24 can you please confirm this?
Thanks
Closing as the solution is correct.