TriPSs / nx-extend

Nx Workspaces builders and tools
MIT License
155 stars 40 forks source link

Can't Build Strapi From Project Root #85

Closed Chudroy closed 1 year ago

Chudroy commented 1 year ago

If I try to build the strapi app from the project root it crashes. If I cd into the strapi app and run the build it works.

When I build from the project root it runs the executor "@nx-extend/strapi:build", in the project.json, but when I run the build from within the app, it runs strapi build in the package.json.

Node: 16 LTS NPM: 18.19.2 Yarn: 1.22.19 strapi: 4.3.9 nx-extend/strapi version 3.1.2

The error I get when I build from the project root is:

ModuleNotFoundError: Module not found: Error: Can't resolve '@strapi/icons/CarretDown' in '/home/ngaritagoitia/Documentos/Playground/nombre-repositorio/apps/cms/node_modules/@strapi/design-system/dist/Select'
Did you mean 'CarretDown.js'?
BREAKING CHANGE: The request '@strapi/icons/CarretDown' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
    at /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/webpack/lib/Compilation.js:2016:28
    at /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/webpack/lib/NormalModuleFactory.js:798:13
    at eval (eval at create (/home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:10:1)
    at /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/webpack/lib/NormalModuleFactory.js:270:22
    at eval (eval at create (/home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:9:1)
    at /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/webpack/lib/NormalModuleFactory.js:434:22
    at /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/webpack/lib/NormalModuleFactory.js:116:11
    at /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/webpack/lib/NormalModuleFactory.js:670:25
    at /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/webpack/lib/NormalModuleFactory.js:855:8
    at /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/webpack/lib/NormalModuleFactory.js:975:5
resolve '@strapi/icons/CarretDown' in '/home/ngaritagoitia/Documentos/Playground/nombre-repositorio/apps/cms/node_modules/@strapi/design-system/dist/Select'
  Parsed request is a module
  using description file: /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/apps/cms/node_modules/@strapi/design-system/package.json (relative path: ./dist/Select)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/apps/cms/node_modules/@strapi/design-system/dist/Select/node_modules doesn't exist or is not a directory
      /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/apps/cms/node_modules/@strapi/design-system/dist/node_modules doesn't exist or is not a directory
      /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/apps/cms/node_modules/@strapi/design-system/node_modules doesn't exist or is not a directory
      /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/apps/cms/node_modules/@strapi/node_modules doesn't exist or is not a directory
      /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/apps/cms/node_modules/node_modules doesn't exist or is not a directory
      looking for modules in /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/apps/cms/node_modules
        existing directory /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/apps/cms/node_modules/@strapi/icons
          using description file: /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/apps/cms/node_modules/@strapi/icons/package.json (relative path: .)
            using exports field: ./dist/CarretDown
              using description file: /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/apps/cms/node_modules/@strapi/icons/package.json (relative path: ./dist/CarretDown)
                Field 'browser' doesn't contain a valid alias configuration
                /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/apps/cms/node_modules/@strapi/icons/dist/CarretDown doesn't exist
      /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/apps/node_modules doesn't exist or is not a directory
      looking for modules in /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules
        existing directory /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/@strapi/icons
          using description file: /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/@strapi/icons/package.json (relative path: .)
            using description file: /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/@strapi/icons/package.json (relative path: ./CarretDown)
              Field 'browser' doesn't contain a valid alias configuration
              /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/@strapi/icons/CarretDown doesn't exist
      /home/ngaritagoitia/Documentos/Playground/node_modules doesn't exist or is not a directory
      /home/ngaritagoitia/Documentos/node_modules doesn't exist or is not a directory
      /home/ngaritagoitia/node_modules doesn't exist or is not a directory
      /home/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory
      looking for modules in /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/@strapi/admin/node_modules
        /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/@strapi/admin/node_modules/@strapi/icons doesn't exist
ModuleNotFoundError: Module not found: Error: Can't resolve '@strapi/icons/CarretDown' in '/home/ngaritagoitia/Documentos/Playground/nombre-repositorio/apps/cms/node_modules/@strapi/design-system/dist/Select'
Did you mean 'CarretDown.js'?
BREAKING CHANGE: The request '@strapi/icons/CarretDown' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
    at /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/webpack/lib/Compilation.js:2016:28
    at /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/webpack/lib/NormalModuleFactory.js:798:13
    at eval (eval at create (/home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:10:1)
    at /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/webpack/lib/NormalModuleFactory.js:270:22
    at eval (eval at create (/home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:9:1)
    at /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/webpack/lib/NormalModuleFactory.js:434:22
    at /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/webpack/lib/NormalModuleFactory.js:116:11
    at /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/webpack/lib/NormalModuleFactory.js:670:25
    at /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/webpack/lib/NormalModuleFactory.js:855:8
    at /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/webpack/lib/NormalModuleFactory.js:975:5
resolve '@strapi/icons/CarretDown' in '/home/ngaritagoitia/Documentos/Playground/nombre-repositorio/apps/cms/node_modules/@strapi/design-system/dist/Select'
  Parsed request is a module
  using description file: /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/apps/cms/node_modules/@strapi/design-system/package.json (relative path: ./dist/Select)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/apps/cms/node_modules/@strapi/design-system/dist/Select/node_modules doesn't exist or is not a directory
      /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/apps/cms/node_modules/@strapi/design-system/dist/node_modules doesn't exist or is not a directory
      /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/apps/cms/node_modules/@strapi/design-system/node_modules doesn't exist or is not a directory
      /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/apps/cms/node_modules/@strapi/node_modules doesn't exist or is not a directory
      /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/apps/cms/node_modules/node_modules doesn't exist or is not a directory
      looking for modules in /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/apps/cms/node_modules
        existing directory /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/apps/cms/node_modules/@strapi/icons
          using description file: /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/apps/cms/node_modules/@strapi/icons/package.json (relative path: .)
            using exports field: ./dist/CarretDown
              using description file: /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/apps/cms/node_modules/@strapi/icons/package.json (relative path: ./dist/CarretDown)
                Field 'browser' doesn't contain a valid alias configuration
                /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/apps/cms/node_modules/@strapi/icons/dist/CarretDown doesn't exist
      /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/apps/node_modules doesn't exist or is not a directory
      looking for modules in /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules
        existing directory /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/@strapi/icons
          using description file: /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/@strapi/icons/package.json (relative path: .)
            using description file: /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/@strapi/icons/package.json (relative path: ./CarretDown)
              Field 'browser' doesn't contain a valid alias configuration
              /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/@strapi/icons/CarretDown doesn't exist
      /home/ngaritagoitia/Documentos/Playground/node_modules doesn't exist or is not a directory
      /home/ngaritagoitia/Documentos/node_modules doesn't exist or is not a directory
      /home/ngaritagoitia/node_modules doesn't exist or is not a directory
      /home/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory
      looking for modules in /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/@strapi/admin/node_modules
        /home/ngaritagoitia/Documentos/Playground/nombre-repositorio/node_modules/@strapi/admin/node_modules/@strapi/icons doesn't exist
TriPSs commented 1 year ago

In what package.json is @strapi/icon located? And what version of the Strapi packages are you using?

Chudroy commented 1 year ago

Hi,

there is a yarn.lock at the project root and one in the strapi admin app. The versions differ. in both

image image

TriPSs commented 1 year ago

Could you remove the yarn.lock in the strapi folder and add the following to your package.json in the root

"workspaces": {
    "packages": [
      "apps/**", // both options can
      "apps/cms"
    ]
  },

You should then also be able to remove the packages from the root.

Chudroy commented 1 year ago

I have followed your instructions. Unfortunately, I am still getting the same error.

Chudroy commented 1 year ago

I did a yarn install and this appeared, also.

image

TriPSs commented 1 year ago

The cms is located at apps/cms right? That package.json with all the Strapi deps are still there?

Could you share that package.json

Chudroy commented 1 year ago

Yes, here you go:

{
  "name": "cms",
  "private": true,
  "version": "0.1.0",
  "description": "A Strapi application",
  "scripts": {
    "develop": "strapi develop",
    "start": "strapi start",
    "build": "strapi build",
    "strapi": "strapi"
  },
  "devDependencies": {},
  "dependencies": {
    "@strapi/strapi": "4.5.2",
    "@strapi/plugin-users-permissions": "4.5.2",
    "@strapi/plugin-i18n": "4.5.2",
    "better-sqlite3": "7.4.6"
  },
  "author": {
    "name": "A Strapi developer"
  },
  "strapi": {
    "uuid": "360f24e3-9193-435f-9202-762280632d53"
  },
  "engines": {
    "node": ">=14.19.1 <=18.x.x",
    "npm": ">=6.0.0"
  },
  "license": "MIT"
}
TriPSs commented 1 year ago

Could you try by adding "@strapi/design-system": "1.2.8",?

Or with the following packages?

    "@strapi/design-system": "1.2.8",
    "@strapi/plugin-i18n": "4.4.5",
    "@strapi/plugin-users-permissions": "4.4.5",
    "@strapi/strapi": "4.4.5",

Atm i'm unable to reproduce the issue with my own Strapi project so not 100% what is causing this.

Chudroy commented 1 year ago

This also, unfortunately has not worked. I will create a new nx and strapi project, and write down all the steps to reproduce the issue.

Chudroy commented 1 year ago

npx create-nx-workspace@latest strapi-workspace --preset=angular --appName=web --style=scss --nxCloud=false --package-manager=yarn

cd strapi-workspace

nvm use 16.18.1 LTS Node 16 version

yarn add @nx-extend/strapi --dev

yarn run nx g @nx-extend/strapi:init cms

in /package.json, in "scripts", change "ng":"nx" to "nx":"nx"

image

yarn nx build cms

and then I get the error in the original post. Also of note right now is that if I use npm to install deps, I get dependency errors for the angular app also. Just all around dep hell right now.

TriPSs commented 1 year ago

Just to be sure, you did run nx g @nx-extend/strapi:init?

Chudroy commented 1 year ago

oh, yeah, I did. I'll edit that into the previous post, oops

TriPSs commented 1 year ago

@Chudroy thanks for the steps, If I change the apps/cms/package.json deps to the following the build works:

  "dependencies": {
    "@strapi/design-system": "1.2.8",
    "@strapi/plugin-i18n": "4.4.5",
    "@strapi/plugin-users-permissions": "4.4.5",
    "@strapi/strapi": "4.4.5",
    "better-sqlite3": "7.4.6"
  },

I think there may be a issue with the newer Strapi, think this error was also one of the reasons why I did not update it yet in my project.

Will have to dig deeper to see why it fails with the newest verison.

Chudroy commented 1 year ago

And it worked! Thanks so much. How did you decide which versions to use? If you find out more, please let me know.

Have a good Monday!

fs-innonova commented 1 year ago

Could you remove the yarn.lock in the strapi folder and add the following to your package.json in the root

"workspaces": {
    "packages": [
      "apps/**", // both options can
      "apps/cms"
    ]
  },

You should then also be able to remove the packages from the root.

If I try to do this then when I run npm i I get this error: npm ERR! code EINVALIDPACKAGENAME npm ERR! Invalid package name "$" of package "$@swc/core": name can only contain URL-friendly characters.

TriPSs commented 1 year ago

@fs-innonova workspaces is something of yarn. Could you try this

TriPSs commented 1 year ago

@Chudroy I think I figured out why it did not work with the newest version: the version of @strapi/strapi that was is used inside @nx-extend/strapi should be the same (or similar minor version) as the one you use in your own project.

I just released @nx-extend/strapi@3.2.0-alpha.1 which is updated to the latest @strapi/strapi and my build (and server) are both working as expected, thing to note is to remove all caches (dist folder and .cache folder inside the strapi app)

My Strapi APP's package json now has these deps:

    "@strapi/design-system": "1.4.0",
    "@strapi/plugin-graphql": "4.5.4",
    "@strapi/plugin-i18n": "4.5.4",
    "@strapi/plugin-seo": "1.7.7",
    "@strapi/plugin-users-permissions": "4.5.4",
    "@strapi/provider-email-sendgrid": "4.5.4",
    "@strapi/strapi": "4.5.4",
TriPSs commented 1 year ago

Going to close this issue now as we now know what caused this.

Chudroy commented 1 year ago

Yep, thanks for the help