Skip to content

Instantly share code, notes, and snippets.

@rabitarochan
Created July 15, 2023 22:57
Show Gist options
  • Save rabitarochan/31ef1536209704923b57190983b9f3ee to your computer and use it in GitHub Desktop.
Save rabitarochan/31ef1536209704923b57190983b9f3ee to your computer and use it in GitHub Desktop.
Kuma UI with Next.js App Router のエラー調査

Kuma UI が Windows 環境で動作しない件について

Kuma UI を Windows で利用した場合にエラーとなる件についての調査メモです。

事象

Windows 環境で Kuma UI を実行したところ、次のエラーが発生します。

image

調査結果 ※WIP

現在の example を Windows 環境で実行すると、3/4 エラーとなります。

報告のあったエラーは、Next App Router 固有の自動だと思われます。 現在、ビルドエラーが Windows 固有のものかが判断付いていないため、引き続き調査中です。

対象 結果 メモ
example/next OK
example/next-app-router NG 報告の合った事象が発生することを確認。
example/vite NG ビルドエラー。調査中。
example/webpack NG ビルドエラー。調査中。

確認方法

  1. pnpm build --filter=<target> で、対象別にビルドができるか確認
  2. pnpm -C ./example/<target> dev で、対象別に開発モードで動作するか確認

(1/4) example/next : OK

確認コマンド pnpm -C ./example/next dev

ビルドエラーが発生せず、Kuma UI が動作することを確認しました。

(2/4) example/next-app-router : NG

確認コマンド pnpm -C ./example/next-app-router dev

現リポジトリーの状態で実行すると、次のエラーで開発サーバーが起動しないことを確認しました。

> pnpm -C .\example\next-app-router dev

> [email protected] dev C:\Users\asamizu\Documents\Workspace\kuma-ui\example\next-app-router
> next dev

- ready started server on 0.0.0.0:3000, url: http://localhost:3000
ReferenceError: process is not defined
    at ../../node_modules/.pnpm/[email protected]/node_modules/react/index.js (kuma.config.ts:2430:5)
    at __require (kuma.config.ts:38:50)
    at ../../packages/core/dist/components/Box/react/index.js (kuma.config.ts:5282:33)
    at __require (kuma.config.ts:38:50)
    at ../../packages/core/dist/components/Box/index.js (kuma.config.ts:5316:30)
    at __require (kuma.config.ts:38:50)
    at ../../packages/core/dist/components/index.js (kuma.config.ts:6429:37)
    at __require (kuma.config.ts:38:50)
    at kuma.config.ts:6495:34
    at Script.runInContext (node:vm:141:12) {
  type: 'ReferenceError'
}
 ELIFECYCLE  Command failed with exit code 1.

一旦 Next App Router のプロジェクトを作成し直したところ、いただいたエラーが再現できました。

(プロジェクト再作成)
> pnpm create next-app@latest
√ What is your project named? ... next-app-router2
√ Would you like to use TypeScript? ... No / *Yes*
√ Would you like to use ESLint? ... No / *Yes*
√ Would you like to use Tailwind CSS? ... *No* / Yes
√ Would you like to use `src/` directory? ... No / *Yes*
√ Would you like to use App Router? (recommended) ... No / *Yes*
√ Would you like to customize the default import alias? ... *No* / Yes
Creating a new Next.js app in C:\Users\rabitarochan\Documents\Workspace\kuma-ui\example\next-app-router2.

(package.json に、@kuma-ui/core と @kuma-ui/next-plugin をそれぞれ追加)
...省略...

(インストール)
> pnpm install

エラー出力

- error C:UsersasamizuDocumentsWorkspacekuma-uiexample
ext-app-router2/.next/cache/kuma/1598ee2760c5daf7661b1dbc244fdff0.css
Module build failed: UnhandledSchemeError: Reading from "C:UsersasamizuDocumentsWorkspacekuma-uiexample
ext-app-router2/.next/cache/kuma/1598ee2760c5daf7661b1dbc244fdff0.css" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "c:" URIs.
Import trace for requested module:
C:UsersasamizuDocumentsWorkspacekuma-uiexample
ext-app-router2/.next/cache/kuma/1598ee2760c5daf7661b1dbc244fdff0.css
./src/app/dynamic.tsx

なお、どの API (styled, css, k) でもスタイルなしではエラーが発生せず、スタイルがつくとエラーとなりました。

styled

import { styled } from "@kuma-ui/core";

// OK
const Component = styled("div")``;

// NG
const Component = styled("div")`
  color: red;
`;

css

import { css } from "@kuma-ui/core";

// OK ※ 'Using the "css" in runtime is not supported.' が表示される。
const Component = <div className={css``}>Hello Kuma UI !</div>;

// NG
const Component = (
  <div
    className={css`
      color: red;
    `}
  >
    Hello Kuma UI !
  </div>
);

k

import { k } from "@kuma-ui/core";

// OK
const Component = <k.div>Hello Kuma UI !</k.div>;

// NG
const Component = <k.div color="red">Hello Kuma UI !</k.div>;

(3/4) Vite : NG ※調査中

確認コマンド pnpm -C ./example/vite dev

次のエラーが発生し、開発サーバーが起動しませんでした。

> pnpm -C .\example\vite dev                  

> [email protected] dev C:\Users\asamizu\Documents\Workspace\kuma-ui\example\vite     
> vite

failed to load config from C:\Users\asamizu\Documents\Workspace\kuma-ui\example\vite\vite.config.ts
error when starting dev server:
Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'C:\Users\asamizu\Documents\Workspace\kuma-ui\packages\core\dist\components\index' imported from C:\Users\asamizu\Documents\Workspace\kuma-ui\packages\core\dist\components\componentList.mjs
    at new NodeError (node:internal/errors:399:5)
    at finalizeResolution (node:internal/modules/esm/resolve:326:11)
    at moduleResolve (node:internal/modules/esm/resolve:945:10)
    at defaultResolve (node:internal/modules/esm/resolve:1153:11)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
    at link (node:internal/modules/esm/module_job:76:36)
 ELIFECYCLE  Command failed with exit code 1.

Vite プロジェクトを 1 から作成して動くことは確認済みなので、こちらも example を再作成して再調査します。

(4/4) Webpack ※調査中

確認コマンド pnpm -C ./example/next dev

次のエラーが発生することを確認しました。

> pnpm -C .\example\webpack start

> [email protected] start C:\Users\asamizu\Documents\Workspace\kuma-ui\example\webpack
> rimraf node_modules/@kuma-ui/core/node_modules/react && webpack serve --mode development   

<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: http://localhost:3000/
<i> [webpack-dev-server] On Your Network (IPv4): http://192.168.0.181:3000/
<i> [webpack-dev-server] On Your Network (IPv6): http://[fe80::a110:22c2:5506:e0c1]:3000/    
<i> [webpack-dev-server] Content not from webpack is served from 'C:\Users\asamizu\Documents\Workspace\kuma-ui\example\webpack\build' directory
asset main.js 1.46 MiB [emitted] (name: main)
asset kuma.css 1.11 KiB [emitted] (name: main)
asset index.html 382 bytes [emitted]
Entrypoint main 1.47 MiB = kuma.css 1.11 KiB main.js 1.46 MiB
runtime modules 43.7 KiB 23 modules
orphan modules 2.96 KiB [orphan] 3 modules
javascript modules 1.32 MiB
  modules by path ../../ 196 KiB
    modules by path ../../node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/ 156 KiB 23 modules
    modules by path ../../node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/ 19.1 KiB 5 modules
    modules by path ../../node_modules/.pnpm/[email protected][email protected]/node_modules/mini-css-extract-plugin/dist/hmr/*.js 5.92 KiB 2 modules
    kuma.css!=!../../packages/webpack-plugin/dist/virtualLoader.js?{"src":".🐻-652625356 { padding: 12px; } .🐻-2839521805 { cursor: pointer; } .🐻-1767578551 { color: orange;font-size: 24px; }"}!../../packages/webpack-plugin/assets/kuma.css 393 bytes [built] [code generated]   
    ../../node_modules/.pnpm/node_modules/events/events.js 14.5 KiB [built] [code generated] 
  modules by path ./ 1.12 MiB
    modules by path ./node_modules/ 1.12 MiB 10 modules
    ./src/index.tsx 250 bytes [built] [code generated]
    ./App.tsx 2.9 KiB [built] [code generated]
css ../../node_modules/.pnpm/[email protected][email protected]/node_modules/css-loader/dist/cjs.js!../../packages/webpack-plugin/dist/virtualLoader.js?{"src":".🐻-652625356 { padding: 12px; } .🐻-2839521805 { cursor: pointer; } .🐻-1767578551 { color: orange;font-size: 24px; }"}!../../packages/webpack-plugin/assets/kuma.css 124 bytes [built] [code generated]

WARNING in ./App.tsx 16:28-31
export 'Box' (imported as 'Box') was not found in '@kuma-ui/core' (module has no exports)    
 @ ./src/index.tsx 2:0-29 6:31-34

WARNING in ./App.tsx 19:44-50
export 'Button' (imported as 'Button') was not found in '@kuma-ui/core' (module has no exports)
 @ ./src/index.tsx 2:0-29 6:31-34

WARNING in ./App.tsx 30:33-36
export 'Box' (imported as 'Box') was not found in '@kuma-ui/core' (module has no exports)    
 @ ./src/index.tsx 2:0-29 6:31-34

ERROR in ./node_modules/@kuma-ui/core/dist/index.mjs 1:0-34
Module not found: Error: Can't resolve './styled' in 'C:\Users\asamizu\Documents\Workspace\kuma-ui\example\webpack\node_modules\@kuma-ui\core\dist'
Did you mean 'styled.js'?
BREAKING CHANGE: The request './styled' 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.
 @ ./App.tsx 8:0-44 16:28-31 19:44-50 30:33-36
 @ ./src/index.tsx 2:0-29 6:31-34

ERROR in ./node_modules/@kuma-ui/core/dist/index.mjs 2:0-24
Module not found: Error: Can't resolve './k' in 'C:\Users\asamizu\Documents\Workspace\kuma-ui\example\webpack\node_modules\@kuma-ui\core\dist'
Did you mean 'k.js'?
BREAKING CHANGE: The request './k' 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.
 @ ./App.tsx 8:0-44 16:28-31 19:44-50 30:33-36
 @ ./src/index.tsx 2:0-29 6:31-34

ERROR in ./node_modules/@kuma-ui/core/dist/index.mjs 3:0-28
Module not found: Error: Can't resolve './css' in 'C:\Users\asamizu\Documents\Workspace\kuma-ui\example\webpack\node_modules\@kuma-ui\core\dist'
Did you mean 'css.js'?
BREAKING CHANGE: The request './css' 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.
 @ ./App.tsx 8:0-44 16:28-31 19:44-50 30:33-36
 @ ./src/index.tsx 2:0-29 6:31-34

ERROR in ./node_modules/@kuma-ui/core/dist/index.mjs 4:0-38
Module not found: Error: Can't resolve './theme' in 'C:\Users\asamizu\Documents\Workspace\kuma-ui\example\webpack\node_modules\@kuma-ui\core\dist'
Did you mean 'theme.js'?
BREAKING CHANGE: The request './theme' 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.
 @ ./App.tsx 8:0-44 16:28-31 19:44-50 30:33-36
 @ ./src/index.tsx 2:0-29 6:31-34

ERROR in ./node_modules/@kuma-ui/core/dist/index.mjs 5:0-29
Module not found: Error: Can't resolve './components' in 'C:\Users\asamizu\Documents\Workspace\kuma-ui\example\webpack\node_modules\@kuma-ui\core\dist'
Did you mean 'index.js'?
BREAKING CHANGE: The request './components' 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.
 @ ./App.tsx 8:0-44 16:28-31 19:44-50 30:33-36
 @ ./src/index.tsx 2:0-29 6:31-34

ERROR in ./node_modules/@kuma-ui/core/dist/index.mjs 6:0-27
Module not found: Error: Can't resolve './registry' in 'C:\Users\asamizu\Documents\Workspace\kuma-ui\example\webpack\node_modules\@kuma-ui\core\dist'
Did you mean 'index.js'?
BREAKING CHANGE: The request './registry' 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.
 @ ./App.tsx 8:0-44 16:28-31 19:44-50 30:33-36
 @ ./src/index.tsx 2:0-29 6:31-34

6 errors have detailed information that is not shown.
Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.

webpack 5.78.0 compiled with 6 errors and 3 warnings in 4675 ms

こちらもプロジェクトを再作成してみようと考えています。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment