vite icon indicating copy to clipboard operation
vite copied to clipboard

Failed to parse source for import analysis because the content contains invalid JS syntax

Open ArthurDanjou opened this issue 3 years ago • 22 comments

Versions

nuxt-vite: 0.0.36 nuxt: 2.15.3

Reproduction

https://github.com/ArthurDanjou/artsite/tree/dev

Description

When i start the dev server with yarn dev, during the bundle i have this error :

 ERROR  Failed to parse source for import analysis because the content contains invalid JS syntax. If you are using JSX, make sure to name the file with the .jsx or .tsx extension.                    09:51:39

  at formatError (node_modules\vite\dist\node\chunks\dep-efe32886.js:43451:46)
  at TransformContext.error (node_modules\vite\dist\node\chunks\dep-efe32886.js:43447:19)
  at TransformContext.transform (node_modules\vite\dist\node\chunks\dep-efe32886.js:44932:22)
  at async Object.transform (node_modules\vite\dist\node\chunks\dep-efe32886.js:43649:30)
  at async transformRequest (node_modules\vite\dist\node\chunks\dep-efe32886.js:59310:29)
  at async warmup (node_modules\nuxt-vite\dist\nuxt-vite.js-vite.js:356:5)
  at async Promise.all (index 1)
  at async warmup (node_modules\nuxt-vite\dist\nuxt-vite.js-vite.js:358:5)
  at async Promise.all (index 7)
  at async warmup (node_modules\nuxt-vite\dist\nuxt-vite.js-vite.js:358:5)
  at async Promise.all (index 4)
  at async warmup (node_modules\nuxt-vite\dist\nuxt-vite.js-vite.js:358:5)
  at async Promise.all (index 0)
  at async warmupViteServer (node_modules\nuxt-vite\dist\nuxt-vite.js-vite.js:360:3)

In addition, I have a question, do we need to add a vite.config.js file ?

ArthurDanjou avatar Mar 31 '21 07:03 ArthurDanjou

Maybe can use rollup hooks transform to transforming custom file types. But I don't know how to do it

morelearn1990 avatar May 23 '21 12:05 morelearn1990

I'm having the same problem here, the terminal show:

Unrestricted file system access to "/@id/defaultexport:C:/Users/OS/.../.nuxt/components/plu
gin.js"


 WARN  For security concerns, accessing files outside of serving allow list will be restricted by default in the future version of Vite. Refer to https://vitejs.dev/config
/#server-fs-allow for more details.


 WARN  Unrestricted file system access to "/@id/defaultexport:C:/Users/OS/.../.nuxt/composition-ap
i/plugin.mjs"

...
Failed to parse source for import analysis because the content contains invalid JS syntax. You may need to install appropriate plugins to handle the .html file for
mat.

  at formatError (node_modules\vite\dist\node\chunks\dep-cc49d7be.js:50135:46)
  at TransformContext.error (node_modules\vite\dist\node\chunks\dep-cc49d7be.js:50131:19)
  at TransformContext.transform (node_modules\vite\dist\node\chunks\dep-cc49d7be.js:73380:22)
  at async Object.transform (node_modules\vite\dist\node\chunks\dep-cc49d7be.js:50336:30)
  at async transformRequest (node_modules\vite\dist\node\chunks\dep-cc49d7be.js:65952:29)
  at async warmup (node_modules\nuxt-vite\dist\nuxt-vite.js-vite.js:386:5)
  at async Promise.all (index 6)
  at async warmup (node_modules\nuxt-vite\dist\nuxt-vite.js-vite.js:388:5)
  at async Promise.all (index 5)
  at async warmup (node_modules\nuxt-vite\dist\nuxt-vite.js-vite.js:388:5)
  at async Promise.all (index 9)
  at async warmup (node_modules\nuxt-vite\dist\nuxt-vite.js-vite.js:388:5)
  at async Promise.all (index 4)
  at async warmup (node_modules\nuxt-vite\dist\nuxt-vite.js-vite.js:388:5)
  at async Promise.all (index 0)
  at async warmupViteServer (node_modules\nuxt-vite\dist\nuxt-vite.js-vite.js:390:3)

prd-y-nguyen avatar Jul 10 '21 08:07 prd-y-nguyen

Had that error on a Vite + Vue 3 + TS project recently when the files were accidentally compiled to .js files as well by my IDE. Removing the compiled files resolved it

TheAlexLichter avatar Jul 14 '21 09:07 TheAlexLichter

export default {
  path: '/setting',
  component: () => import('./view.vue')
};

this will case error. change path: '/setting' to path: '//setting', error gone.

please fix this.

mbossX avatar Jul 27 '21 09:07 mbossX

Getting the same error when using nuxt-content with Markdown.

dankimio avatar Aug 03 '21 00:08 dankimio

Same issue here

divinrkz avatar Feb 09 '22 10:02 divinrkz

Any news on this issue? I'm having this issue with Nuxt3 / Vue3 /Cypress

thecoconutdream avatar Mar 04 '22 15:03 thecoconutdream

Any news on this issue? I'm having this issue with Nuxt3 / Vue3 /Cypress

If you face this issue with Nuxt3, please open an issue in the framework repo and feel free to link this one inside.

TheAlexLichter avatar Mar 04 '22 22:03 TheAlexLichter

I feel like this issue might have a simple cause: running vite in the wrong directory. It keeps happening to me but it's always because I'm not in my app's root folder

kewp avatar Mar 16 '22 11:03 kewp

i meet the error info : Failed to parse source for import analysis because the content contains invalid JS syntax. You may need to install appropriate plugins to handle the .css file format. env:nuxt-rc2,primevue,only css use "primeicons/primeicons.css", //icons

wohui avatar May 10 '22 02:05 wohui

it's work &::before { //content: ''; }

====== it's don't work &::before { content: ''; }

it's work .carousel { display: block; @media(max-width: 1200px) { display: grid; // grid-template-areas: // "gallery gallery" // "arrowLeft arrowRight"; grid-template-columns: 1fr 1fr; } }

it's don't work .carousel { display: block; @media(max-width: 1200px) { display: grid; grid-template-areas: "gallery gallery" "arrowLeft arrowRight"; grid-template-columns: 1fr 1fr; } }

ohot2015 avatar May 11 '22 08:05 ohot2015

had same issue,I fixed it by changing .js to .jsx in the file that had the error

phpjscoding avatar Jun 10 '22 01:06 phpjscoding

had same issue,I fixed it by changing .js to .jsx in the file that had the error

Also this worked for me. Thank you!

itzAmka avatar Jun 27 '22 16:06 itzAmka

I'm now getting this error for a file called

index.test.jsx

 src/Pages/WelcomePage/views/SelectUser/index.test.jsx [ src/Pages/WelcomePage/views/SelectUser/index.test.jsx ]
Error: Failed to parse source for import analysis because the content contains invalid JS syntax. If you are using JSX, make sure to name the file with the .jsx or .tsx extension.
 ❯ formatError node_modules/.pnpm/[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-80fe9c6b.js:39055:46
 ❯ TransformContext.error node_modules/.pnpm/[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-80fe9c6b.js:39051:19```

<img width="812" alt="image" src="https://user-images.githubusercontent.com/216566/176856577-e14c8b60-e9c0-4b41-8a05-47227ab3e818.png">

quantuminformation avatar Jul 01 '22 08:07 quantuminformation

I get following error:

Failed to parse source for import analysis because the content contains invalid JS syntax. If you are using JSX, make sure to name the file with the .jsx or .tsx extension. (x4)
Failed to parse source for import analysis because the content contains invalid JS syntax. If you are using JSX, make sure to name the file with the .jsx or .tsx extension. (x5)
1:30:27 am [vite] Internal server error: Failed to parse source for import analysis because the content contains invalid JS syntax. If you are using JSX, make sure to name the file with the .jsx or .tsx extension.
  Plugin: vite:import-analysis
  File: D:/ok/ok/ok_web_components/node_modules/@thisbeyond/solid-dnd/dist/source/drag-drop-context.jsx?v=09bbb5ec

I downgrade to "vite": "3.0.9", and it solved the problem.

kapilpipaliya avatar Sep 09 '22 20:09 kapilpipaliya

had same issue,I fixed it by changing .js to .jsx in the file that had the error

ok it works but I want to make it accept .js instead of .jsx

ahm-r7 avatar Sep 27 '22 21:09 ahm-r7

Had that error on a Vite + Vue 3 + TS project recently when the files were accidentally compiled to .js files as well by my IDE. Removing the compiled files resolved it

Can you expand on this? I'm not following: what was compiled to js by accident, and what should it have been compiled to instead?

vecter avatar Oct 11 '22 18:10 vecter

In my case I had a class in separate file which I imported somewhere.

I didn't close brackets properly: eg.

(new MyClass( 'data')) .doSomething( // <- missing closing bracket

And for what ever reason, error is saying

Internal server error: Failed to parse source for import analysis because the content contains invalid JS syntax. If you are using JSX, make sure to name the file with the .jsx or .tsx extension.

and is pointing to import (for what ever bizare reason) instead of where class instantiation is missing brackets.

Hope it helps.

DimitrijeD avatar Nov 18 '22 20:11 DimitrijeD

Any news on this issue? I'm having this issue with nuxt 3.0.0, @nuxtjs/tailwind, histoire @histoire/plugin-nuxt @histoire/plugin-vue

AnjaRoseBikes avatar Nov 21 '22 17:11 AnjaRoseBikes

Failed to parse source for import analysis because the content contains invalid JS syntax. If you are using JSX, make sure to name the file with the .jsx or .tsx extension.

ekunemmanuel avatar Nov 22 '22 00:11 ekunemmanuel

In my case it helped to set the language attribute explicit to typescript in the script tag of my Vue components:

<script setup lang="ts">

AnjaRoseBikes avatar Nov 22 '22 07:11 AnjaRoseBikes

Vite is amazing, and super fast... but it should accept JS files and not force us to rewrite all our files to JSX, isn't there any fix for this?.. searched everywhere

kingeke avatar Dec 11 '22 01:12 kingeke