[英]Loading babel.config error with Svelte + Vite app
I'm building a new app with Svelte and Vite and I would like to use a jest test with it.我正在用 Svelte 和 Vite 构建一个新的应用程序,我想用它做一个笑话测试。 I configured it as usual but I have this information about an error:
我像往常一样配置它,但我有以下关于错误的信息:
tests/App.spec.js
● Test suite failed to run
/Users/ewakadziolka/Desktop/svelte/aloes/babel.config.js: Error while loading config - You appear to be using a native ECMAScript module configuration file, which is only supported when running Babel asynchronously.
at loadCjsOrMjsDefault (node_modules/@babel/core/lib/config/files/module-types.js:82:13)
at loadCjsOrMjsDefault.next (<anonymous>)
at readConfigJS (node_modules/@babel/core/lib/config/files/configuration.js:215:47)
at readConfigJS.next (<anonymous>)
at Function.<anonymous> (node_modules/@babel/core/lib/gensync-utils/async.js:27:3)
at evaluateSync (node_modules/gensync/index.js:251:28)
at Function.sync (node_modules/gensync/index.js:89:14)
at sync (node_modules/@babel/core/lib/gensync-utils/async.js:78:25)
at sync (node_modules/gensync/index.js:182:19)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 2.681 s
Ran all test suites related to changed files.
Watch Usage: Press w to show more.
An App.一个应用程序。 svelte for a moment is very easy:
苗条一会儿很容易:
<main>
<h1>Hello word!</h1>
</main>
my babel.congig.js is like this:我的 babel.congig.js 是这样的:
module.exports = { presets: [["@babel/preset-env", { targets: { node: "current" } }]],
};
and my package.json like this:我的 package.json 是这样的:
{
"name": "aloes",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"test": "jest --watch"
},
"devDependencies": {
"@babel/preset-env": "^7.18.9",
"@sveltejs/vite-plugin-svelte": "^1.0.1",
"@testing-library/dom": "^8.16.0",
"@testing-library/svelte": "^3.1.3",
"@testing-library/user-event": "^14.2.6",
"babel-jest": "^28.1.3",
"jest": "^28.1.3",
"jest-environment-jsdom": "^28.1.3",
"svelte": "^3.49.0",
"svelte-jester": "^2.3.2",
"vite": "^3.0.0"
},
"jest": {
"transform": {
"^.+\\.svelte$": "svelte-jester",
"^.+\\.js$": "babel-jest"
},
"testEnvironment": "jsdom"
}
}
This configuration worked very well when I used rollup to build an app.当我使用 rollup 构建应用程序时,此配置运行良好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.