hperrin / svelte-material-ui

Svelte Material UI Components
https://sveltematerialui.com/
Apache License 2.0
3.32k stars 284 forks source link

yargs throws error "Module loop: this module is already being loaded" about smui-theme #463

Open jeromecc opened 2 years ago

jeromecc commented 2 years ago

Describe the bug I'm using smui with SvelteKit, adapter-node and building on Docker (node:17).

Weird thing is that building on my laptop with the same node version does not reproduce this error and the app works seamlessly...

All versions of smui-theme from 6.0.0-beta.16 to 4.0.2 produce this bug.

Any idea? Thanks.

Additional context ``

frontend@0.0.1 prepare svelte-kit sync && npm run smui-theme-light && npm run smui-theme-dark frontend@0.0.1 smui-theme-light smui-theme compile static/smui.css -i src/theme Compiling SMUI Styles... /app/node_modules/smui-theme/node_modules/yargs/build/index.cjs:2772 throw err;
^
Error: Module loop: this module is already being loaded.

1 │ @use 'smui-theme';
│ ^^^^^^^^^^^^^^^^^

node_modules/smui-theme/_index.scss 1:1 root stylesheet
at Object._newRenderError (/app/node_modules/smui-theme/node_modules/sass/sass.dart.js:2203:19)
at Object._wrapException (/app/node_modules/smui-theme/node_modules/sass/sass.dart.js:2023:16)
at StaticClosure._renderSync (/app/node_modules/smui-theme/node_modules/sass/sass.dart.js:2000:18)
at Object.Primitives_applyFunction (/app/node_modules/smui-theme/node_modules/sass/sass.dart.js:6505:30)
at Object.Function_apply (/app/node_modules/smui-theme/node_modules/sass/sass.dart.js:13832:16)
at _callDartFunctionFast (/app/node_modules/smui-theme/node_modules/sass/sass.dart.js:15538:16)
at Object.renderSync (/app/node_modules/smui-theme/node_modules/sass/sass.dart.js:15516:18)
at Object.handler (/app/node_modules/smui-theme/bin/index.js:50:27)
at Object.runCommand (/app/node_modules/smui-theme/node_modules/yargs/build/index.cjs:446:48)
at Object.parseArgs [as _parseArgs] (/app/node_modules/smui-theme/node_modules/yargs/build/index.cjs:2697:57) {
formatted: 'Error: Module loop: this module is already being loaded.\n' +
' ╷\n' +
"1 │ @use 'smui-theme';\n" +
' │ ^^^^^^^^^^^^^^^^^\n' +
' ╵\n' +
' node_modules/smui-theme/_index.scss 1:1 root stylesheet',
line: 1,
column: 1,
file: '/app/node_modules/smui-theme/_index.scss',
status: 1
}
Node.js v17.8.0
npm notice
npm notice New minor version of npm available! 8.5.5 -> 8.11.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.11.0
npm notice Run npm install -g npm@8.11.0 to update!
npm notice
npm ERR! code 1
npm ERR! path /app
npm ERR! command failed
npm ERR! command sh -c svelte-kit sync && npm run smui-theme-light && npm run smui-theme-dark
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-05-30T09_48_34_687Z-debug-0.log
The command '/bin/sh -c npm ci' returned a non-zero code: 1
ERROR: Service 'nodeserver' failed to build : Build failed ``

lancesnider commented 2 years ago

Did you ever figure this out? I'm getting the same issue.

lancesnider commented 2 years ago

I found the solution in another thread: https://github.com/hperrin/svelte-material-ui/issues/256

You need to run this first:

npx smui-theme template src/theme
vhscom commented 1 year ago

It is not good practice to use npx inside a docker container for idempotent builds. In order to satisfy the SMUI v6 need to have a theme file and static directory in place so it can run its prepare script as part of the build you would be better off copying the minimal amount of source needed to allow prepare to run. Doing so will improve caching of the Docker build and ensure changes to the npx script output/use do not affect your working builds.

Here's an example snippet for the Dockerfile:

COPY package*.json .
COPY src/theme ./src/theme
RUN mkdir static
RUN npm ci --cache .npm
COPY . .

And then later, re-run prepare so it's using the CI version of the SMUI framework (and not what was in dev):

RUN npm run prepare