Trying to setup SolidJS with Webpack and ts-loader.
Keep getting an issue on return
functions.
What exactly am i missing in the loader to solve the issue ?
import { render } from "solid-js/web";
const App = () => {
// return "Hello World" // this works!
return (<div> Hello World </div>) // this doesnt work!
};
render(App, document.getElementById("app"));
Error Log Output:
> webpack --watch --progress --config webpack.config.js
asset index.js 1.56 KiB [emitted] (name: main)
./src/test.tsx 290 bytes [built] [code generated]
ERROR in ./src/test.tsx 6:12
Module parse failed: Unexpected token (6:12)
File was processed with these loaders:
* ./node_modules/ts-loader/index.js
You may need an additional loader to handle the result of these loaders.
| const App = () => {
| // return "Hello World" // this works!
> return (<div> Hello World </div>); // this doesnt work!
| };
| render(App, document.getElementById("app"));
webpack 5.47.0 compiled with 1 error in 2081 ms
webpack.config
const path = require('path');
module.exports = {
mode: 'development',
entry: './src/test.tsx',
module: {
rules: [
{
use: 'ts-loader',
test: /\.(ts|tsx)?$/,
exclude: /node_modules/
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js']
},
output: {
filename: 'index.js',
path: path.resolve(__dirname, 'dist')
}
}
UPDATE:
# tsconfig.json
{
"compilerOptions": {
"jsx": "preserve",
"jsxImportSource": "solid-js",
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "node",
"esModuleInterop": false
},
"include": ["src/**/*.ts", "src/**/*.tsx"],
"exclude": ["node_modules"]
}
Solved:
#webpack module rules:
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: ['solid'],
},
},
{
loader: 'ts-loader',
},
]
}
]
},