Dom
Dom

Reputation: 45

Attempting to run strapi gives module parse error

I'm attempting to run a strapi project via npm on Ubuntu 20.04 with "npm run develop". The code is from a group project of mine, and no one else is encountering these issues.

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.

I've attempted the solutions on these threads: Strapi develop command failed, How to fix "Module build failed (from ./node_modules/babel-loader/lib/index.js):"?

Neither of which have worked.

I've also attempted:

Here's my project's package.json, which should hopefully provide more context

{
  "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"
}

Am I just improperly using my package.json file? Any tips or direction would be greatly appreciated.

Upvotes: 4

Views: 1802

Answers (1)

Michał
Michał

Reputation: 46

1. Better solution.

Check if your Strapi project is nested within another project that uses babel/webpack. I had some old files in my directory with all my projects. When I removed them, it works.

2. Workaround solution (With every packages update, it will be back to an earlier version)

  1. in your strapi folder, go to → node_modules/strapi-admin/webpack.config.js
  2. locate the line → require.resolve('@babel/preset-env')
  3. replace it with [require.resolve('@babel/preset-env'),{ targets: 'defaults' }],
  4. run the command - npm run dev

Upvotes: 3

Related Questions