typescript를 사용하여 React를 설정하려고합니다.이 튜토리얼은 here입니다. react-select
을 설치했지만 컴파일러 오류 Build: Cannot find module 'react-select'
을 참조하려고 할 때 cmd 행에서 webpack을 실행하려고하면 동일한 오류가 발생합니다.Typescript/Webpack : 'react-select'모듈을 찾을 수 없습니다.
github에 대한 수정으로 제안 된 다음 로더를 포함 시키려고했지만 동일한 오류가 발생합니다.
{
test: /\.js$/,
include: path.join(__dirname, 'node_modules', 'react-select'),
loader: 'jsx-loader',
}
아이디어가 있으십니까?
UPDATE :
tsconfig.json
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "es6",
"jsx": "react"
},
"files": [
"./typings/index.d.ts",
"./src/components/Hello.tsx",
"./src/index.tsx"
]
}
package.json : webpack
는 데피해야와
{
"name": "react-typescript-setup",
"version": "1.0.0",
"main": "./dist/bundle.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"webpack": "webpack -w"
},
"author": "",
"license": "ISC",
"dependencies": {
"react": "^15.3.1",
"react-dom": "^15.3.1",
"react-select": "^1.0.0-rc.1"
},
"devDependencies": {
"css-loader": "^0.25.0",
"react-select": "^1.0.0-rc.1",
"source-map-loader": "^0.1.5",
"style-loader": "^0.13.1",
"ts-loader": "^0.8.2",
"typings": "^1.3.3"
},
"description": ""
}
webpack.config.js
var path = require('path');
module.exports = {
entry: "./src/index.tsx",
output: {
path: __dirname,
filename: "./dist/bundle.js",
},
// Enable sourcemaps for debugging webpack's output.
devtool: "source-map",
debug: true,
resolve: {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: ["", ".webpack.js", ".web.js", ".ts", ".tsx", ".js"]
},
module: {
loaders: [
// All files with a '.ts' or '.tsx' extension will be handled by 'ts-loader'.
{ test: /\.tsx?$/, loader: "ts-loader" },
{
test: /\.css$/,
loader: 'style!css-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]'
}
],
preLoaders: [
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{ test: /\.js$/, loader: "source-map-loader" }
]
},
// When importing a module whose path matches one of the following, just
// assume a corresponding global variable exists and use that instead.
// This is important because it allows us to avoid bundling all of our
// dependencies, which allows browsers to cache those libraries between builds.
externals: {
"react": "React",
"react-dom": "ReactDOM"
},
};
흠, 그게 제가 가지고있는 것입니다. 반응 선택을위한 타이핑을 설치했는데, 그것은 오류를 변경했습니다, 지금은이 구조를 사용하여 가져올 수 없다고 말합니다. –
무엇이>이 구조? –
ES6 import 문 중 하나 인 Import *를 Select, Import에서 선택, 가져 오기 {Select}에서 .. –