Feliz ํ
ํ๋ฆฟ์ผ๋ก ์ฒ์๋ถํฐ ์์ํ์ฌ npm start
๋ก ์คํํ ๋ค์ App.fs
์ ์๋ HelloWorld
React Component์ ์ด๋ฆ์ HelloWorlds
๋ณ๊ฒฝํ์ต๋๋ค.
๊ฒฐ๊ณผ์ ์ผ๋ก Fable์ ๊ฒฝ๊ณ ์์ด ์ ์ปดํ์ผ๋์ง๋ง React๋ ๋ฐํ์์ ๋ถํํฉ๋๋ค(์๋ฌด๊ฒ๋ ๋ ๋๋ง๋์ง ์์).
Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
at createFiberFromTypeAndProps (react-dom.development.js?61bb:25058)
at createFiberFromElement (react-dom.development.js?61bb:25086)
at reconcileSingleElement (react-dom.development.js?61bb:14052)
at reconcileChildFibers (react-dom.development.js?61bb:14112)
at reconcileChildren (react-dom.development.js?61bb:16997)
at updateHostRoot (react-dom.development.js?61bb:17599)
at beginWork (react-dom.development.js?61bb:19077)
at HTMLUnknownElement.callCallback (react-dom.development.js?61bb:3945)
at Object.invokeGuardedCallbackDev (react-dom.development.js?61bb:3994)
at invokeGuardedCallback (react-dom.development.js?61bb:4056)
์ผ์ข
์ ์บ์ฑ ๋ฌธ์ ์ธ ๊ฒ ๊ฐ์ต๋๋ค. ์ฐํ ์์ฒด์ ์๋์ง ๋๋ feliz ํ๋ฌ๊ทธ์ธ์ ์๋์ง ํ์คํ์ง ์์ต๋๋ค. .fable
๋๋ ํ ๋ฆฌ๋ฅผ ์ง์ด ํ ์ ์์ ์ผ๋ก ์๋ํฉ๋๋ค.
์๋ ํ์ธ์ @theimowski ์ ๋ ์ต๊ทผ์ ์ด ๋ฌธ์ ๋ฅผ ์ ํ์ต๋๋ค. ๋๋ ๊ทธ๊ฒ์ ์กฐ์ฌํด์ผ ํ์ง๋ง @alfonsogarciacaro ๊ฐ ๊ทธ๊ฒ์ ๋ํด ๋ ๋ง์ด ์๊ณ ์์ ๊ฒ์ ๋๋ค. ์ต์ Fable v3.1.10์ ์ฌ์ฉํด ๋ณผ ์๋ ์์ต๋๊น? ํ ํ๋ฆฟ์ 3.1.5์ ์์ต๋๋ค.
์ฐํ๋ฌธ์ ์ธ๋ฏ
3.1.11๋ก ์๋ํด ์ฃผ์๊ฒ ์ต๋๊น? ์ด๊ฒ์ ์๋ง๋ https://github.com/fable-compiler/Fable/issues/2413 ๊ณผ ๊ด๋ จ์ด ์์ ๊ฒ์ ๋๋ค.
v3.1.11์์ ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋ ๊ฒ์ผ๋ก ํ์ธ๋์์ผ๋ฏ๋ก @theimowski ๋ ์๋ํด ๋ณผ ์ ์์ต๋๊น?
์ฌ์ ํ Fable 3.1.11์์ ์์ํ ๋๋ก ์์ ํ ์๋ํ์ง ์์ต๋๋ค.
์ด๊ฒ์ ์กฐ๊ธ ๋ ์กฐ์ฌํ๋ ค๊ณ :
HelloWorld
๋ณ๊ฒฝ -> HelloWorlds
ํ์ง๋ง App.fs
์์๋ง ๋ณ๊ฒฝ:Compiling src/App.fsproj...
F# compilation finished in 17ms
Fable compilation finished in 31ms
/Users/theimowski/sandbox/feliz/rename/src/Main.fs(9,1): (12,2) error FSHARP: A unique overload for method 'render' could not be determined based on type information prior to this program point. A type annotation may be needed.
Known types of arguments: 'a * Browser.Types.HTMLElement
Candidates:
- static member ReactDOM.render : element:(unit -> Fable.React.ReactElement) * container:Browser.Types.HTMLElement -> 'a0
- static member ReactDOM.render : element:Fable.React.ReactElement * container:Browser.Types.HTMLElement -> 'a (code 41)
/Users/theimowski/sandbox/feliz/rename/src/Main.fs(10,9): (10,19) error FSHARP: The value, constructor, namespace or type 'HelloWorld' is not defined. Maybe you want one of the following:
HelloWorlds (code 39)
Watching src
โน ๏ฝขwdm๏ฝฃ: Compiling...
โ ๏ฝขwdm๏ฝฃ: assets by status 3.64 MiB [cached] 1 asset
assets by path *.js 71.9 KiB
asset app.js 66.3 KiB [emitted] (name: app)
asset app.cf083007398aca78c7c4.hot-update.js 5.54 KiB [emitted] [immutable] [hmr] (name: app)
asset app.cf083007398aca78c7c4.hot-update.json 27 bytes [emitted] [immutable] [hmr]
Entrypoint app 3.71 MiB = vendors.js 3.64 MiB app.js 66.3 KiB app.cf083007398aca78c7c4.hot-update.js 5.54 KiB
cached modules 1.38 MiB [cached] 74 modules
runtime modules 29.3 KiB 13 modules
./src/App.fs.js 2.75 KiB [built] [code generated]
WARNING in ./src/Main.fs.js 8:35-45
export 'HelloWorld' (imported as 'HelloWorld') was not found in './App.fs.js' (possible exports: HelloWorlds)
webpack 5.14.0 compiled with 1 warning in 139 ms
โน ๏ฝขwdm๏ฝฃ: Compiled with warnings.
FSHARP ์ปดํ์ผ ์ค๋ฅ๊ฐ ์์ง๋ง webpack์ ์ค๋ฅ๋ฅผ ์ปดํ์ผํ๊ณ ๊ฒฝ๊ณ ๋ก ์ฒ๋ฆฌํ๊ณ WDS๋ ํ์ด์ง๋ฅผ ์๋ก ๊ณ ์นจํ๊ณ ํ๋ฉด์ ๋ ๋๋ง๋ ์ฃผ์ ์์ React ์ค๋ฅ๋ฅผ ๋ณผ ์ ์์ต๋๋ค.
HelloWorld
๋ณ๊ฒฝ -> HelloWorlds
in Main.fs
: ์ปดํ์ผ์ ์ฑ๊ณตํ์ง๋ง React๋ ์คํจํ๊ณ ์ค๋ฅ๋ ๊ฐ๋ฐ ์ฝ์์ ๊ธฐ๋ก๋ฉ๋๋ค.
ํ์ด์ง ์๋ก ๊ณ ์นจ - ๋์ค์ ์ ์๋ํฉ๋๋ค.
์ด๊ฒ์ ์ผ์ข ์ ๊ฒฝ์ ์กฐ๊ฑด ๋ฌธ์ ์ผ ์ ์์ต๋๋ค. Feliz ํ ํ๋ฆฟ์์ ๋ ํ์ผ์ ์ด๋ฆ์ ๋์์ ๋ฐ๊พธ๋ฉด ์ผ๋ฐ์ ์ผ๋ก ์ ์๋ํ์ง๋ง ์ฝ๊ฐ ๋ ํฐ ํ๋ก์ ํธ์์๋ ๊ตฌ์ฑ ์์์ ์ด๋ฆ์ ๋ฐ๊ฟ ๋ ๋ก๊ทธ์์ ๋ค์ ๋์์ ๋ณผ ์ ์์ต๋๋ค(์ฐธ๊ณ ์ค๊ฐ์ ๊ฒฝ๊ณ ):
Compiling src/Client/Client.fsproj...
F# compilation finished in 67ms
Compiled src/Client/App.fsโน ๏ฝขwdm๏ฝฃ: Compiling...
โ ๏ฝขwdm๏ฝฃ: Hash: 615d2643d48416b2ff41
Version: webpack 4.43.0
Time: 456ms
Built at: 03/17/2021 9:30:04 PM
Asset Size Chunks Chunk Names
app.e781f5f7185376d5a0d3.hot-update.js 9.4 KiB app [emitted] [immutable] [hmr] app
app.js 4.69 MiB app [emitted] app
e781f5f7185376d5a0d3.hot-update.json 45 bytes [emitted] [immutable] [hmr]
index.html 670 bytes [emitted]
+ 1 hidden asset
Entrypoint app = vendors~app.js app.js app.e781f5f7185376d5a0d3.hot-update.js
[./src/Client/App.fs.js] 1.32 KiB {app} [built]
+ 382 hidden modules
WARNING in ./src/Client/App.fs.js 28:21-32
"export 'HelloWorlds' was not found in './Index.fs.js'
Child html-webpack-plugin for "index.html":
1 asset
Entrypoint undefined = index.html
4 modules
โน ๏ฝขwdm๏ฝฃ: Compiled with warnings.
Fable compilation finished in 1635ms
Compiled src/Client/Index.fsWatching src
โน ๏ฝขwdm๏ฝฃ: Compiling...
โน ๏ฝขwdm๏ฝฃ: Hash: 837f9683f0ac04dcc729
Version: webpack 4.43.0
Time: 820ms
Built at: 03/17/2021 9:30:06 PM
Asset Size Chunks Chunk Names
615d2643d48416b2ff41.hot-update.json 45 bytes [emitted] [immutable] [hmr]
app.615d2643d48416b2ff41.hot-update.js 141 KiB app [emitted] [immutable] [hmr] app
app.js 4.69 MiB app [emitted] app
index.html 670 bytes [emitted]
+ 1 hidden asset
Entrypoint app = vendors~app.js app.js app.615d2643d48416b2ff41.hot-update.js
[./src/Client/Index.fs.js] 29.5 KiB {app} [built]
+ 382 hidden modules
Child html-webpack-plugin for "index.html":
1 asset
Entrypoint undefined = index.html
4 modules
โน ๏ฝขwdm๏ฝฃ: Compiled successfully.
@theimowski ์ ๋ ์ด๊ฒ์ด ์ง์ ์ ํ์ผ์ ๋ณ๊ฒฝํ ๋ ์ ์ฒด ํ์ด์ง ์๋ก ๊ณ ์นจ์ ํธ๋ฆฌ๊ฑฐํด์ผ ํ๋ ๋น ๋ฅธ ์๋ก ๊ณ ์นจ ํ๋ฌ๊ทธ์ธ์ ๊ฒฝ์ฐ ์ค์ ๋ก ์ด๊ฒ์ด ๊ฐ์ฅ ์ค์ํ ๊ฒฝ์ฐ์ผ ์ ์๋ค๊ณ ์๊ฐํฉ๋๋ค.
์ธ์ ๊ฐ ์ด๋ก ์ ํ์ธํ ํ์๊ฐ ์์ต๋๋ค. ์ฐธ์กฐ๋ ๊ตฌ์ฑ ์์๊ฐ ์ง์ ์ ํ์ผ์ ์์ผ๋ฉด ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ง ์์ต๋๋ค. ๋ฐ๋ผ์ App.fs -> Middle.fs -> Main.fs(์ง์ ์ )๊ฐ ์๊ณ App.fs ๋๋ Middle.fs๋ง ๋ณ๊ฒฝํ๋ ๊ฒฝ์ฐ
๋น์ ๋ ์ด๊ฒ์ ์๋ ํ ์ ์์ต๋๊น?
@theimowski ๋๋ react-refresh#330 ์ ๋ฌธ์ ๋ฅผ ๊ต์ฐจ ๊ฒ์ํ์ต๋๋ค.
์ต์ ์นํฉ์ ์ฌ์ฉํ ๋ ๋ฐ์ ์๋ก ๊ณ ์นจ์ด ๋ฐ์ํ๋ฏ๋ก ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋ ๋๊น์ง ์นํฉ v4๋ก ๋กค๋ฐฑํ๊ณ v3.6์์ ์๋ํ๋ Feliz ํ ํ๋ฆฟ(์ด์ ๋ ๋ง์ ์์ ๊ตฌ์ฑ ์์ ํฌํจ)์ ๊ฒ์ํ์ต๋๋ค.
๊ฐ์ฌํฉ๋๋ค. ์, ์ค์ ๋ก ์๋ก์ด feliz ํ
ํ๋ฆฟ์ ์ฌ์ฉํ๋ฉด ์๋ก ๊ณ ์นจ ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋์์ต๋๋ค.
F# ์ปดํ์ผ ์ค๋ฅ๊ฐ ์นํฉ ์๋ก ๊ณ ์นจ์ ์คํจํ๋ค๋ฉด ๋ ์ข์ง ์์์๊น? ์๋๋ฉด ๋ฌ์ฑํ๊ธฐ ์ด๋ ค์ด ์ผ์
๋๊น?
Fable 2.* ๋ฐ webpack dev ์๋ฒ๋ก ๋์๊ฐ์ F# ์ปดํ์ผ ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ฉด ์๋ก ๊ณ ์นจ์ด ํธ๋ฆฌ๊ฑฐ๋์ง ์์ต๋๋ค.
F# ์ปดํ์ผ ์ค๋ฅ๊ฐ ์นํฉ ์๋ก ๊ณ ์นจ์ ์คํจํ๋ค๋ฉด ๋ ์ข์ง ์์์๊น? ์๋๋ฉด ๋ฌ์ฑํ๊ธฐ ์ด๋ ค์ด ์ผ์ ๋๊น?
๋ถ๊ฐ๋ฅํ ๊ฒ์ ์๋๋๋ค: ์๋ง๋ _์๋์ ์ผ๋ก_ ์นํฉ์ด ํ๋ ์ผ์ ๊นจ๋จ๋ฆฌ๊ธฐ ์ํด ์ผ๋ถ ๊ตฌ๋ฌธ ์ค๋ฅ๊ฐ ์๋ JS ์ฝ๋๋ฅผ ๋ด๋ณด๋ด์ผ ํ ๊ฒ์ ๋๋ค.
ํ์ฌ ์ํฉ์ ๊ด์ฐฎ๋ค๊ณ ์๊ฐํฉ๋๋ค. ์นํฉ์ด ๊ฒฝ๊ณ ๋ฅผ ๋ด๋ณด๋ด๊ณ ์์ ๋ Fable์ด ์ค๋ฅ๋ฅผ ๋ด๋ณด๋ด๊ณ ์๊ธฐ ๋๋ฌธ์ ๊ฐ๋ฐ์๊ฐ ํด๊ฒฐํด์ผ ํ๋ ์ฐ์ ์์๊ฐ ๋ ๋๊ธฐ ๋๋ฌธ์ ๋๋ค. Fable(์ปดํ์ผ) ์ค๋ฅ๊ฐ ์์ ๋๋ฉด ์นํฉ ๊ฒฝ๊ณ ๋ ์ฌ๋ผ์ง๋๋ค. ๋ด๊ฐ ๋ญ๊ฐ๋ฅผ ๋์น๊ณ ์์ต๋๊น?
๋ด ๊ฐ์ธ์ ์ธ ์ทจํฅ์ ์คํจํ ๋จ๊ณ๋ก ์ธํด ๋ค์ ๋จ๊ณ๊ฐ ์คํ๋์ง ์๋ ๊ฒ์ ๋๋ค. ๊ทธ๋ ์ง ์์ผ๋ฉด ๋ธ๋ผ์ฐ์ ์์ ์๋ก๊ณ ์นจ๋๋ ๋ด์ฉ์ ๋ณผ ์ ์๊ณ F# ์ฝ๋๊ฐ ์ค์ ๋ก ์ปดํ์ผ๋์ง ์๋ ๋์ ๋ชจ๋ ๊ฒ์ด ์ ์์ด๋ผ๊ณ ์์ผ ์ ์์ต๋๋ค.
๊ทธ๋ฌ๋ react-refresh๋ ํฐ๋ฏธ๋์ ์นํฉ ๊ฒฝ๊ณ ๊ฐ ํ์๋๋๋ผ๋ ๋ธ๋ผ์ฐ์ ์ ์ค๋ฅ ๋ฉ์์ง์ ํจ๊ป ๋นจ๊ฐ์ ์ค๋ฅ ํ์ด์ง๋ฅผ ํ์ํฉ๋๋ค.
์๊ฒ ์ต๋๋ค. ๊ทธ๋ ๋ค๋ฉด ๊ด์ฐฎ์ต๋๋ค.
์ ์ผํ ๋ฌธ์ ๋ https://github.com/pmmmwh/react-refresh-webpack-plugin/issues/330 ์์ ์ค๋ช
ํ ๊ฒ์
๋๋ค.