frappe / frappe_docker

Docker images for production and development setups of the Frappe framework and ERPNext
MIT License
1.38k stars 1.31k forks source link

Error: Cannot find module 'chalk' #908

Closed smmitc closed 2 years ago

smmitc commented 2 years ago

Description of the issue

With ERPNext v14 I'm not able to create a new Website Theme. I've tested Versions up to 14.0.3.

Context information (for bug reports)

Installation of the test environment:

git clone https://github.com/frappe/frappe_docker
cd frappe_docker
cp example.env .env
mkdir ~/gitops
docker compose -f compose.yaml \
  -f overrides/compose.noproxy.yaml \
  -f overrides/compose.erpnext.yaml \
  -f overrides/compose.mariadb.yaml \
  -f overrides/compose.redis.yaml \
  config > ~/gitops/docker-compose.yml

docker compose --project-name example -f ~/gitops/docker-compose.yml up -d
docker exec example-backend-1 bench new-site localhost --mariadb-root-password 123 --admin-password secret --install-app erpnext

Steps to reproduce the issue

  1. Go to Website
  2. Click Website Theme
  3. Click Add Website Theme
  4. Enter a name, e.g. 'Test'
  5. Click Save

Observed result

Cannot find module chalk

Expected result

New Website Theme without errors.

Stacktrace / full error message if available

Error: Cannot find module 'chalk'
Require stack:
- /home/frappe/frappe-bench/apps/frappe/esbuild/utils.js
- /home/frappe/frappe-bench/apps/frappe/esbuild/sass_options.js
- /home/frappe/frappe-bench/apps/frappe/generate_bootstrap_theme.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:101:18)
at Object. (/home/frappe/frappe-bench/apps/frappe/esbuild/utils.js:3:15)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/home/frappe/frappe-bench/apps/frappe/esbuild/utils.js',
'/home/frappe/frappe-bench/apps/frappe/esbuild/sass_options.js',
'/home/frappe/frappe-bench/apps/frappe/generate_bootstrap_theme.js'
]
}

Someone solved this issue in this post by doing

Step 1: bench setup socketio
Step 2: bench setup requirements

However as far as I know this has to be done when creating the image.

revant commented 2 years ago

I'm able to save website theme on my kubernetes setup

it may be because the pod initContainer copies all js assets from nginx image into assets in sites volume.

may be you can try something like this if it works?

https://gist.github.com/revant/6a67f775aa8198f9b306f32d6872799f#file-erpnext-v13-yaml-L177-L189

smmitc commented 2 years ago

I have the same problem with my kubernetes setup using the official chart. Then I've tested the setup using docker with the same results. The initContainer of gunicorn is:

  initContainers:
  - args:
    - /usr/share/nginx/html/assets
    - /home/frappe/frappe-bench/sites
    command:
    - cp
    - -fR
    image: frappe/erpnext-nginx:v14.0.3
    imagePullPolicy: IfNotPresent
    name: populate-assets
    resources: {}
    securityContext:
      capabilities:
        add:
        - CAP_CHOWN
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    volumeMounts:
    - mountPath: /home/frappe/frappe-bench/sites/assets
      name: assets-cache
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: kube-api-access-jvmdx
      readOnly: true

I tried the suggested commands in docker. There is no /data directory:

docker exec -it example-frontend-1 /bin/sh
/ $ ls
bin                   docker-entrypoint.sh  lib                   opt                   run                   sys                   var
dev                   etc                   media                 proc                  sbin                  tmp
docker-entrypoint.d   home                  mnt                   root                  srv                   usr

The sites volume is mounted to /usr/share/nginx/html/sites and it contains a directory named assets. So the correct command is cp -fR /usr/share/nginx/html/assets /usr/share/nginx/html/sites, right? But then I get the error

cp: can't create '/usr/share/nginx/html/sites/assets/assets.json': Permission denied
cp: can't create '/usr/share/nginx/html/sites/assets/assets-rtl.json': Permission denied
cp: can't create directory '/usr/share/nginx/html/sites/assets/erpnext': Permission denied
cp: can't create directory '/usr/share/nginx/html/sites/assets/frappe': Permission denied
cp: can't create directory '/usr/share/nginx/html/sites/assets/payments': Permission denied
revant commented 2 years ago

the commands run in separate container called populate-assets, you need to execute docker run with appropriate -v volume mounted in mentioned locations.

docker exec executes command in existing container.

smmitc commented 2 years ago

Thanks! The commands are working with docker run if I run them as root with --user 0.

docker run --rm --name populate_assets --user 0 \
> -v frappe_docker_assets:/data/assets:rw \
> -v frappe_docker_sites:/data/sites:rw \
> frappe/erpnext-nginx:v14.0.3 sh -c "cp -fR /usr/share/nginx/html/assets /data; touch /data/sites/.build";

Unfortunately that does not solve my problem.

revant commented 2 years ago

as root with --user 0

then you can chown as required?

smmitc commented 2 years ago

I didn't use chown. If I execute the commands as default user I get a lot of errors:

...
cp: can't create '/data/assets/erpnext/js/contact.js': File exists
cp: can't create '/data/assets/erpnext/js/shopping_cart.js': File exists
cp: can't create '/data/assets/erpnext/js/website_theme.js': File exists
cp: can't create '/data/assets/erpnext/js/communication.js': File exists
cp: can't create '/data/assets/erpnext/js/financial_statements.js': File exists
cp: can't create '/data/assets/erpnext/js/agriculture/ternary_plot.js': File exists
cp: can't create '/data/assets/erpnext/js/bank_reconciliation_tool/dialog_manager.js': File exists
cp: can't create '/data/assets/erpnext/js/bank_reconciliation_tool/data_table_manager.js': File exists
cp: can't create '/data/assets/erpnext/js/bank_reconciliation_tool/number_card.js': File exists
cp: can't create '/data/assets/erpnext/js/utils.js': File exists
cp: can't create '/data/assets/erpnext/js/account_tree_grid.js': File exists
cp: can't create '/data/assets/payments/node_modules/.yarn-integrity': File exists
cp: can't create '/data/assets/payments/.gitkeep': File exists
cp: can't create '/data/assets/payments/js/razorpay.js': File exists

Probably that's because /data/assets is owned by root:

docker run --rm --name populate_assets \
-v frappe_docker_assets:/data/assets:rw \
-v frappe_docker_sites:/data/sites:rw \
frappe/erpnext-nginx:v14.0.3 sh -c "ls -la /data/assets"
total 28
drwxr-xr-x    5 root     root          4096 Sep  2 07:09 .
drwxr-xr-x    4 root     root          4096 Sep  2 13:14 ..
-rw-r--r--    1 root     root           996 Sep  2 07:09 assets-rtl.json
-rw-r--r--    1 root     root          2980 Sep  2 07:09 assets.json
drwxr-xr-x    8 root     root          4096 Sep  2 07:10 erpnext
drwxr-xr-x   11 root     root          4096 Sep  1 07:11 frappe
drwxr-xr-x    4 root     root          4096 Sep  2 07:10 payments
smmitc commented 2 years ago

Oh, you want me to execute this, right?

docker run --rm --name populate_assets --user 0 \
-v frappe_docker_assets:/data/assets:rw \
-v frappe_docker_sites:/data/sites:rw \
frappe/erpnext-nginx:v14.0.3 sh -c "cp -fR /usr/share/nginx/html/assets /data; touch /data/sites/.build; chown -R 1000:1000 /data/assets";

The error ist still the same. Are the commands above correct?

smmitc commented 2 years ago

Does nobody else have this problem? It's a complete new environment created by the commands in my first post.

shahin-trunk commented 2 years ago

We are also facing this issue. @revant any possible fix for this?

revant commented 2 years ago

can you try building the assets image like this? https://github.com/frappe/frappe_docker/issues/919#issuecomment-1239305640

I think solved it for me. If that works, I'll remove frappe/assets-builder and update documentation to build assets using frappe/bench

smmitc commented 2 years ago

Thank you very much, that solved the issue for me! :thumbsup: Now finally I'm able to use ERPNext v14 :smiley:

revant commented 2 years ago

Follow https://github.com/frappe/frappe_docker/issues/919