尝试 运行 strapi 给出模块解析错误
Attempting to run strapi gives module parse error
我正在尝试 运行 通过 npm 在 Ubuntu 20.04 上使用“npm 运行 开发”进行 strapi 项目。该代码来自我的一个小组项目,没有其他人遇到这些问题。
Error: ./.cache/plugins/strapi-plugin-content-manager/admin/src/components/RepeatableComponent/Banner.js 2:87
Module parse failed: Unexpected token (2:87)
File was processed with these loaders:
* ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
我尝试了这些线程的解决方案:
Strapi develop command failed,
两者均无效。
我也尝试过:
- 正在重新安装Ubuntu
- 正在重新安装 Babel
- 降级或尝试不同版本的 Babel
这是我的项目 package.json,希望它能提供更多背景信息
{
"name": "my-project",
"private": true,
"version": "0.1.0",
"description": "A Strapi application",
"scripts": {
"develop": "strapi develop",
"start": "strapi start",
"build": "strapi build",
"strapi": "strapi"
},
"devDependencies": {
"@babel/core": "^7.13.15",
"@babel/preset-env": "^7.13.15",
"babel-loader": "^8.2.2",
"webpack": "^5.33.2"
},
"dependencies": {
"knex": "0.21.18",
"sqlite3": "5.0.0",
"strapi": "3.5.4",
"strapi-admin": "3.5.4",
"strapi-connector-bookshelf": "3.5.4",
"strapi-plugin-content-manager": "3.5.4",
"strapi-plugin-content-type-builder": "3.5.4",
"strapi-plugin-email": "3.5.4",
"strapi-plugin-graphql": "3.5.4",
"strapi-plugin-upload": "3.5.4",
"strapi-plugin-users-permissions": "3.5.4",
"strapi-utils": "3.5.4"
},
"author": {
"name": "A Strapi developer"
},
"strapi": {
"uuid": "ab32cbf0-3e4d-42ea-a078-e816435ef1f7"
},
"engines": {
"node": ">=10.16.0 <=14.x.x",
"npm": "^6.0.0"
},
"license": "MIT"
}
我只是不正确地使用了 package.json 文件吗?任何提示或指导将不胜感激。
1.更好的解决方案。
检查您的 Strapi 项目是否嵌套在另一个使用 babel/webpack 的项目中。我的所有项目目录中都有一些旧文件。当我删除它们时,它起作用了。
2。解决方案(每次更新软件包,它都会回到早期版本)
- 在您的 strapi 文件夹中,转到 →
node_modules/strapi-admin/webpack.config.js
- 定位线→
require.resolve('@babel/preset-env')
- 替换为
[require.resolve('@babel/preset-env'),{ targets: 'defaults' }],
- 运行 命令 -
npm run dev
我正在尝试 运行 通过 npm 在 Ubuntu 20.04 上使用“npm 运行 开发”进行 strapi 项目。该代码来自我的一个小组项目,没有其他人遇到这些问题。
Error: ./.cache/plugins/strapi-plugin-content-manager/admin/src/components/RepeatableComponent/Banner.js 2:87
Module parse failed: Unexpected token (2:87)
File was processed with these loaders:
* ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
我尝试了这些线程的解决方案:
Strapi develop command failed,
两者均无效。
我也尝试过:
- 正在重新安装Ubuntu
- 正在重新安装 Babel
- 降级或尝试不同版本的 Babel
这是我的项目 package.json,希望它能提供更多背景信息
{
"name": "my-project",
"private": true,
"version": "0.1.0",
"description": "A Strapi application",
"scripts": {
"develop": "strapi develop",
"start": "strapi start",
"build": "strapi build",
"strapi": "strapi"
},
"devDependencies": {
"@babel/core": "^7.13.15",
"@babel/preset-env": "^7.13.15",
"babel-loader": "^8.2.2",
"webpack": "^5.33.2"
},
"dependencies": {
"knex": "0.21.18",
"sqlite3": "5.0.0",
"strapi": "3.5.4",
"strapi-admin": "3.5.4",
"strapi-connector-bookshelf": "3.5.4",
"strapi-plugin-content-manager": "3.5.4",
"strapi-plugin-content-type-builder": "3.5.4",
"strapi-plugin-email": "3.5.4",
"strapi-plugin-graphql": "3.5.4",
"strapi-plugin-upload": "3.5.4",
"strapi-plugin-users-permissions": "3.5.4",
"strapi-utils": "3.5.4"
},
"author": {
"name": "A Strapi developer"
},
"strapi": {
"uuid": "ab32cbf0-3e4d-42ea-a078-e816435ef1f7"
},
"engines": {
"node": ">=10.16.0 <=14.x.x",
"npm": "^6.0.0"
},
"license": "MIT"
}
我只是不正确地使用了 package.json 文件吗?任何提示或指导将不胜感激。
1.更好的解决方案。
检查您的 Strapi 项目是否嵌套在另一个使用 babel/webpack 的项目中。我的所有项目目录中都有一些旧文件。当我删除它们时,它起作用了。
2。解决方案(每次更新软件包,它都会回到早期版本)
- 在您的 strapi 文件夹中,转到 →
node_modules/strapi-admin/webpack.config.js
- 定位线→
require.resolve('@babel/preset-env')
- 替换为
[require.resolve('@babel/preset-env'),{ targets: 'defaults' }],
- 运行 命令 -
npm run dev