我的应用程序使用.ts,.js和.jsx文件进行编译并运行。现在,我尝试将.jsx文件更改为.tsx,它会中断。
如何解决此编译错误:
ts-loader: Using typescript@1.6.2 and C:\users\ruser\Desktop\Downloads\divinote\site\tsconfig.json 67% 226/234 build modulesModuleParseError: Module parse failed: C:\users\ruser\Desktop\Downloads\divinote\site\node_modules\ts-loader\index.js?cacheDirectory!C:\users\ruser\Desktop\Downloads\divinote\site\src\app\views\header\DiviAppBar.tsx
Line 15: Unexpected token <
You may need an appropriate loader to handle this file type.
| }
| DiviAppBar.prototype.render = function () {
| return (<AppBar />);
| };
| return DiviAppBar;
at DependenciesBlock.<anonymous> (C:\users\ruser\Desktop\Downloads\divinote\site\node_modules\webpack\lib\NormalModule.js:113:20)
at DependenciesBlock.onModuleBuild (C:\users\ruser\Desktop\Downloads\divinote\site\node_modules\webpack-core\lib\NormalModuleMixin.js:310:10)
at nextLoader (C:\users\ruser\Desktop\Downloads\divinote\site\node_modules\webpack-core\lib\NormalModuleMixin.js:275:25)
at C:\users\ruser\Desktop\Downloads\divinote\site\node_modules\webpack-core\lib\NormalModuleMixin.js:292:15
at context.callback (C:\users\ruser\Desktop\Downloads\divinote\site\node_modules\webpack-core\lib\NormalModuleMixin.js:148:14)
at Object.loader (C:\users\ruser\Desktop\Downloads\divinote\site\node_modules\ts-loader\index.js:431:5)
at WEBPACK_CORE_LOADER_EXECUTION (C:\users\ruser\Desktop\Downloads\divinote\site\node_modules\webpack-core\lib\NormalModuleMixin.js:155:71)
at runSyncOrAsync (C:\users\ruser\Desktop\Downloads\divinote\site\node_modules\webpack-core\lib\NormalModuleMixin.js:155:93)
at nextLoader (C:\users\ruser\Desktop\Downloads\divinote\site\node_modules\webpack-core\lib\NormalModuleMixin.js:290:3)
at C:\users\ruser\Desktop\Downloads\divinote\site\node_modules\webpack-core\lib\NormalModuleMixin.js:259:5
at Storage.finished (C:\users\ruser\Desktop\Downloads\divinote\site\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:38:16)
at C:\users\ruser\Desktop\Downloads\divinote\site\node_modules\graceful-fs\graceful-fs.js:76:16
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:404:3) 69% 337/338 build moduleschild_process.js:484
当我编译这段代码时:
"use strict";
import React = require('react');
import AppBar = require('material-ui/lib/app-bar');
class DiviAppBar extends React.Component
{
render()
{
return (
<AppBar />
);
}
}
export = DiviAppBar;
与此webpack配置文件:
'use strict';
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var path = require('path');
var rootPath = __dirname; //site
var srcPath = path.join(rootPath, 'src'); //site/src
module.exports =
{
bail: true,
cache: true,
context: rootPath,
debug: true,
devtool: 'inline-source-map', //'eval-cheap-module-source-map','inline-source-map'
target: 'web',
devServer:
{
contentBase: './dist',
historyApiFallback: true
},
entry:
{
app: path.join(srcPath, 'app/main.jsx'),
lib: ['react', 'react-router']
},
output:
{
path: path.join(rootPath, 'dist'),
publicPath: '',
filename: '[name].js',
library: ['[name]', '[name]'],
pathInfo: true
},
resolve:
{
root: srcPath,
extensions: ['', '.js', '.jsx', '.ts', '.tsx'],
modulesDirectories: ['node_modules', 'src', 'typings']
},
module:
{
loaders:
[
{test: /\.js$/, loader: 'babel-loader?cacheDirectory', exclude: /(node_modules|bower_components)/ },
{test: /\.jsx$/, loader: 'babel-loader?cacheDirectory', exclude: /(node_modules|bower_components)/ },
{test: /\.ts$/, loader: 'ts-loader?cacheDirectory', exclude: /(node_modules|bower_components)/ },
{test: /\.tsx$/, loader: 'ts-loader?cacheDirectory', exclude: /(node_modules|bower_components)/ },
{test: /\.scss$/, loaders: ['style', 'css', 'sass']},
{test: /\.png$/, loader: 'file-loader'},
{test: /\.jpg$/, loader: 'file-loader'},
{test: /\.jpeg$/, loader: 'file-loader'},
{test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'file-loader?mimetype=image/svg+xml'},
{test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader?mimetype=application/font-woff"},
{test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader?mimetype=application/font-woff"},
{test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader?mimetype=application/octet-stream"},
{test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader"},
]
},
plugins:
[
new CopyWebpackPlugin
([
{ from: 'src/images', to: 'images' }
]),
new webpack.optimize.CommonsChunkPlugin('lib', 'lib.js'),
new HtmlWebpackPlugin
({
inject: true,
template: 'src/index.html'
}),
new webpack.NoErrorsPlugin()
]
};
和这个tsconfig.json文件:
{
"compilerOptions":
{
"jsx": "preserve",
"noImplicitAny": true,
"module": "commonjs",
"removeComments": false,
"sourceMap": true,
"target": "es5"
},
"files": [],
"exclude":
[
"node_modules",
"dist"
]
}
第一个问题与 Martin 提到的“ jsx”配置有关。将“ jsx”设置为“反应”。
第二个问题与您的代码有关。像这样更改它:
class DiviAppBar extends React.Component<Props, State> ...
为道具创建一个界面,为状态创建另一个界面。如果没有,请使用空对象。
class DiviAppBar extends React.Component<{}, {}> ...
模块解析失败:意外令牌Reactjs? ./src/index.js 6:4模块解析失败时出错:意外标记(6:4)您可能需要适当的加载程序来处理此文件类型,目前没有配置加载程序来处理此文件。看见https://webpack.js.org/concepts#loaders || ReactDOM.render( |document.getElementById('app')|); @multi./
我试图在eclipse中用maven构建一个spark应用程序,但我遇到了一个编译失败。我修正了系统变量,给它提供到JDK的路径,而不是到JRE的路径,如下所示: 并且我将这个字符串添加到变量中,但是没有起作用。因此,我尝试不使用如下但没有新内容。 因此,我尝试通过eclipse来指出我的JDK,如下所示:,我也选择了JDK,但这个解决方案也不起作用,所以我决定使用cmd来修复它: 我检查了,结果
大家好。有人能帮帮我吗?我只是创建react应用程序,然后我立即启动它。然后我得到了类似这样的错误。我不知道出了什么问题 编译失败。./src/index.js 1:68模块解析失败:使用以下加载程序处理了意外的令牌(1:68)文件: null
在两台不同的笔记本电脑上使用maven构建相同的项目。一个是运行良好,一个是显示错误。 状态:两个系统的配置相同。 使用的命令:mvn clean install-DskipTests=true 错误: 我什至尝试删除所有内容,例如再次创建. m2文件夹。
我尝试匹配这个表达式: * ^X-Spam-Flag:是的 我用这个代码: 但是我有这个错误: PHP警告:preg_match():编译失败:在偏移量0处没有任何重复 regex和*和^有问题,但我能纠正吗?
2017-05-23T15:14:03.19+0000[STG/17]出---->下载的应用程序包(59M)2017-05-23T15:14:03.36+0000[STG/0]出站失败:Buildpack编译步骤失败2017-05-23T15:14:03.36+0000[STG/0]错误2017-05-23T15:14:03.46+0000[API/0]错误遇到错误:应用程序在Buildpack编
确切的错误信息是
我在 Groovy 控制台中测试了以下代码,两者都按预期失败:第一个测试: 第二个测试: 等价物在Grails中运行(即类被实例化并在单元测试中使用),但不会抛出异常。例如: 我可以知道为什么会有差异吗?谢谢。