inferno-hyperscript hyperscript-helpers 声明错误
inferno-hyperscript hyperscript-helpers declaration error
我正在使用:
我有这 3 行代码:
import h from 'inferno-hyperscript';
import hh from 'hyperscript-helpers';
const html = hh(h);
这段代码给我这个错误:
TypeError: hyperscript_helpers_1.default is not a function
我的 package.json
是:
{
"name": "frontend",
"version": "0.0.1",
"private": true,
"description": "Typescript inferno prove",
"main": "index.js",
"scripts": {
"build": "webpack",
"start": "webpack-dev-server --inline"
},
"author": "Leonardo Saracini",
"license": "MIT",
"engines": {
"node": "7.7.4"
},
"dependencies": {
"@types/ramda": "^0.24.4",
"classnames": "^2.2.5",
"hyperscript": "^2.0.2",
"inferno": "^3.6.4",
"inferno-hyperscript": "^3.6.4",
"hyperscript-helpers": "^3.0.3",
"inferno-redux": "^3.6.4",
"ramda": "^0.24.1",
"redux": "^3.7.2"
},
"devDependencies": {
"@types/classnames": "^2.2.0",
"awesome-typescript-loader": "^3.2.1",
"css-loader": "^0.28.4",
"ejs-loader": "^0.3.0",
"file-loader": "^0.11.2",
"html-webpack-plugin": "^2.29.0",
"source-map-loader": "^0.2.1",
"style-loader": "^0.18.2",
"typescript": "^2.4.2",
"webpack": "^3.3.0",
"webpack-bundle-analyzer": "^2.8.3",
"webpack-dev-server": "2.5.1"
}
}
我的 webpack.config.js 是:
var webpack = require('webpack');
var path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');
//var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
// definePlugin takes raw strings and inserts them, so you can put strings of JS if you want.
var definePlugin = new webpack.DefinePlugin({
__DEV__: JSON.stringify(JSON.parse(process.env.BUILD_DEV || 'true')),
__PRERELEASE__: JSON.stringify(JSON.parse(process.env.BUILD_PRERELEASE || 'false'))
});
module.exports = {
entry: path.resolve(__dirname, 'src/index.ts'), //entrata da compilare. Se ne possono aggiungere molte creando vari profili
output: {
filename: 'bundle.js', //file di output dove mettere il compilato
path: path.resolve(__dirname, 'dist'),
publicPath: '/'
},
devServer: {
hot: true, // Tell the dev-server we're using HMR
contentBase: path.resolve(__dirname, 'dist'),
publicPath: '/'
},
devtool: "inline-source-map",
plugins: [
definePlugin,
new webpack.LoaderOptionsPlugin({
debug: true
}),
new HtmlWebpackPlugin({
title: 'Prima prova',
template: 'src/index.ejs'
}),
new webpack.HotModuleReplacementPlugin() // Enable HMR
//, new BundleAnalyzerPlugin()
],
module: {
rules: [// rules was named loaders in webpack 1 or 2; but is be renamed "rules" in now
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
{
test: /\.ejs$/,
loader: 'ejs-loader'
},
{
test: /\.tsx?$/,
loader: 'awesome-typescript-loader',
options: {
transpileOnly: true
}
},
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{
test: /\.js$/,
enforce: 'pre',
loader: 'source-map-loader'
},
{ test: /\.(png|jpg)$/, loader: 'url-loader?limit=8192' }, // inline base64 URLs for <=8k images, direct URLs for the rest
{ test: /\.css$/, use: ['style-loader', 'css-loader'] },
{ test: /\.(png|svg|jpg|gif)$/,
use: [
'file-loader'
]
},
{ test: /\.(woff|woff2|eot|ttf|otf)$/,
use: [
'file-loader'
]
}
]
},
resolve: {
modules: [__dirname, 'node_modules'],
// Add `.ts` and `.tsx` as a resolvable extension.
extensions: ['.webpack.js', '.web.js', '.ts', '.tsx', '.js', '.json'] // note if using webpack 1 you'd also need a '' in the array as well
}
};
我的tsconfig.json是:
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"lib": ["es6", "es7", "dom"],
"types": [ "inferno" ],
"noImplicitAny": true,
"allowJs": false,
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"preserveConstEnums": true,
"outDir": "./dist/",
"listFiles": true,
"sourceMap": true,
"jsx": "preserve",
"noImplicitReturns": false,
"noFallthroughCasesInSwitch": true,
"experimentalDecorators": false,
"noUnusedLocals": true,
"strictNullChecks": true,
"removeComments": false
},
"exclude": [ "node_modules" ],
"include": [
"./typing.d.ts",
"./src/**/*.ts",
"./src/**/*.tsx"
],
"compileOnSave": false,
"formatCodeOptions": {
"indentSize": 2,
"tabSize": 2,
"newLineCharacter": "\n",
"convertTabsToSpaces": true,
"insertSpaceAfterCommaDelimiter": true,
"insertSpaceAfterSemicolonInForStatements": true,
"insertSpaceBeforeAndAfterBinaryOperators": true,
"insertSpaceAfterKeywordsInControlFlowStatements": true,
"insertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
"insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
"placeOpenBraceOnNewLineForFunctions": false,
"placeOpenBraceOnNewLineForControlBlocks": false
},
"atom": {
"rewriteTsconfig": true
}
}
我的typings.json是:
{
"dependencies": {
"debug": "registry:npm/debug#2.0.0+20160723033700",
"ramda": "registry:dt/ramda#0.0.0+20170322181526"
},
"globalDependencies": {
"classnames": "registry:dt/classnames#0.0.0+20161113184211",
"hyperscript": "registry:dt/hyperscript#0.0.0+20161005184000",
"node": "registry:dt/node#7.0.0+20170322231424",
"redux": "registry:dt/redux#3.5.2+20160703092728"
}
}
我找不到声明此代码的正确方式。
我在 React
等其他框架上找到了很多使用 hyperscript 和 hyperscript-helpers 的示例,但没有混合使用 webpack、inferno 和 typescript 的示例。
有人知道正确的语法吗?
错误是触发执行行 const html = hh(h);
最好的问候
此错误类型的解决方案是将此 tsconfig.json 更改为:
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"lib": ["es6", "es7", "dom"],
至:
{
"compilerOptions": {
"module": "es6",
"target": "es6",
"lib": ["es6", "es7", "dom"],
我正在使用:
我有这 3 行代码:
import h from 'inferno-hyperscript';
import hh from 'hyperscript-helpers';
const html = hh(h);
这段代码给我这个错误:
TypeError: hyperscript_helpers_1.default is not a function
我的 package.json
是:
{
"name": "frontend",
"version": "0.0.1",
"private": true,
"description": "Typescript inferno prove",
"main": "index.js",
"scripts": {
"build": "webpack",
"start": "webpack-dev-server --inline"
},
"author": "Leonardo Saracini",
"license": "MIT",
"engines": {
"node": "7.7.4"
},
"dependencies": {
"@types/ramda": "^0.24.4",
"classnames": "^2.2.5",
"hyperscript": "^2.0.2",
"inferno": "^3.6.4",
"inferno-hyperscript": "^3.6.4",
"hyperscript-helpers": "^3.0.3",
"inferno-redux": "^3.6.4",
"ramda": "^0.24.1",
"redux": "^3.7.2"
},
"devDependencies": {
"@types/classnames": "^2.2.0",
"awesome-typescript-loader": "^3.2.1",
"css-loader": "^0.28.4",
"ejs-loader": "^0.3.0",
"file-loader": "^0.11.2",
"html-webpack-plugin": "^2.29.0",
"source-map-loader": "^0.2.1",
"style-loader": "^0.18.2",
"typescript": "^2.4.2",
"webpack": "^3.3.0",
"webpack-bundle-analyzer": "^2.8.3",
"webpack-dev-server": "2.5.1"
}
}
我的 webpack.config.js 是:
var webpack = require('webpack');
var path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');
//var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
// definePlugin takes raw strings and inserts them, so you can put strings of JS if you want.
var definePlugin = new webpack.DefinePlugin({
__DEV__: JSON.stringify(JSON.parse(process.env.BUILD_DEV || 'true')),
__PRERELEASE__: JSON.stringify(JSON.parse(process.env.BUILD_PRERELEASE || 'false'))
});
module.exports = {
entry: path.resolve(__dirname, 'src/index.ts'), //entrata da compilare. Se ne possono aggiungere molte creando vari profili
output: {
filename: 'bundle.js', //file di output dove mettere il compilato
path: path.resolve(__dirname, 'dist'),
publicPath: '/'
},
devServer: {
hot: true, // Tell the dev-server we're using HMR
contentBase: path.resolve(__dirname, 'dist'),
publicPath: '/'
},
devtool: "inline-source-map",
plugins: [
definePlugin,
new webpack.LoaderOptionsPlugin({
debug: true
}),
new HtmlWebpackPlugin({
title: 'Prima prova',
template: 'src/index.ejs'
}),
new webpack.HotModuleReplacementPlugin() // Enable HMR
//, new BundleAnalyzerPlugin()
],
module: {
rules: [// rules was named loaders in webpack 1 or 2; but is be renamed "rules" in now
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
{
test: /\.ejs$/,
loader: 'ejs-loader'
},
{
test: /\.tsx?$/,
loader: 'awesome-typescript-loader',
options: {
transpileOnly: true
}
},
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{
test: /\.js$/,
enforce: 'pre',
loader: 'source-map-loader'
},
{ test: /\.(png|jpg)$/, loader: 'url-loader?limit=8192' }, // inline base64 URLs for <=8k images, direct URLs for the rest
{ test: /\.css$/, use: ['style-loader', 'css-loader'] },
{ test: /\.(png|svg|jpg|gif)$/,
use: [
'file-loader'
]
},
{ test: /\.(woff|woff2|eot|ttf|otf)$/,
use: [
'file-loader'
]
}
]
},
resolve: {
modules: [__dirname, 'node_modules'],
// Add `.ts` and `.tsx` as a resolvable extension.
extensions: ['.webpack.js', '.web.js', '.ts', '.tsx', '.js', '.json'] // note if using webpack 1 you'd also need a '' in the array as well
}
};
我的tsconfig.json是:
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"lib": ["es6", "es7", "dom"],
"types": [ "inferno" ],
"noImplicitAny": true,
"allowJs": false,
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"preserveConstEnums": true,
"outDir": "./dist/",
"listFiles": true,
"sourceMap": true,
"jsx": "preserve",
"noImplicitReturns": false,
"noFallthroughCasesInSwitch": true,
"experimentalDecorators": false,
"noUnusedLocals": true,
"strictNullChecks": true,
"removeComments": false
},
"exclude": [ "node_modules" ],
"include": [
"./typing.d.ts",
"./src/**/*.ts",
"./src/**/*.tsx"
],
"compileOnSave": false,
"formatCodeOptions": {
"indentSize": 2,
"tabSize": 2,
"newLineCharacter": "\n",
"convertTabsToSpaces": true,
"insertSpaceAfterCommaDelimiter": true,
"insertSpaceAfterSemicolonInForStatements": true,
"insertSpaceBeforeAndAfterBinaryOperators": true,
"insertSpaceAfterKeywordsInControlFlowStatements": true,
"insertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
"insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
"placeOpenBraceOnNewLineForFunctions": false,
"placeOpenBraceOnNewLineForControlBlocks": false
},
"atom": {
"rewriteTsconfig": true
}
}
我的typings.json是:
{
"dependencies": {
"debug": "registry:npm/debug#2.0.0+20160723033700",
"ramda": "registry:dt/ramda#0.0.0+20170322181526"
},
"globalDependencies": {
"classnames": "registry:dt/classnames#0.0.0+20161113184211",
"hyperscript": "registry:dt/hyperscript#0.0.0+20161005184000",
"node": "registry:dt/node#7.0.0+20170322231424",
"redux": "registry:dt/redux#3.5.2+20160703092728"
}
}
我找不到声明此代码的正确方式。
我在 React
等其他框架上找到了很多使用 hyperscript 和 hyperscript-helpers 的示例,但没有混合使用 webpack、inferno 和 typescript 的示例。
有人知道正确的语法吗?
错误是触发执行行 const html = hh(h);
最好的问候
此错误类型的解决方案是将此 tsconfig.json 更改为:
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"lib": ["es6", "es7", "dom"],
至:
{
"compilerOptions": {
"module": "es6",
"target": "es6",
"lib": ["es6", "es7", "dom"],