【发布时间】:2016-05-24 02:20:36
【问题描述】:
我有一个运行良好的客户端应用程序(使用 Webpack/Babel 进行转译和编译)。
我正在尝试使用 Node 渲染此应用服务器端,但出现此错误:
TypeError: C:/[PROJECT_PATH]/src/_base/common/components/general/AComponent.js: Property value expected type of string but got null
at Object.validate (C:\[PROJECT_PATH]\node_modules\babel-types\lib\definitions\index.js:153:13)
at validate (C:\[PROJECT_PATH]\node_modules\babel-types\lib\index.js:269:9)
at Object.builder (C:\[PROJECT_PATH]\node_modules\babel-types\lib\index.js:222:7)
at File.<anonymous> (C:\[PROJECT_PATH]\node_modules\babel-core\lib\transformation\file\index.js:329:56)
at File.addImport (C:\[PROJECT_PATH]\node_modules\babel-core\lib\transformation\file\index.js:336:8)
at C:\[PROJECT_PATH]\node_modules\babel-plugin-react-transform\lib\index.js:257:46
at Array.map (native)
at ReactTransformBuilder.initTransformers (C:\[PROJECT_PATH]\node_modules\babel-plugin-react-transform\lib\index.js:255:40)
at ReactTransformBuilder.build (C:\[PROJECT_PATH]\node_modules\babel-plugin-react-transform\lib\index.js:164:41)
at PluginPass.Program (C:\[PROJECT_PATH]\node_modules\babel-plugin-react-transform\lib\index.js:331:17)
它发生在任何导入的组件上。 我知道组件本身可以工作,因为它们在客户端模式下工作。
这是我的 index.js(与客户端应用程序中相同的 babel 配置):
require('babel-register')({
presets:["es2015", "stage-0",'react'],
highlightCode: false,
sourceMaps: "both",
env: {
development: {
plugins: [
'transform-decorators-legacy',
["react-transform", {
transforms: [{
imports: ['react'],
locals: ['module']
}]
}]
]
}
}
});
require('./renderer.js');
这是我的 renderer.js:
import React, { Component } from 'react'
import Router, {match, RoutingContext } from 'react-router'
// this works :
import AnyActions from 'path/to/actions/AnyActions'
// this don't
import AnyComponent from 'path/to/any/component'
其他的都被注释掉了!
我尝试导入这个简单的 AComponent:
import React, { Component, PropTypes } from 'react'
export default class AComponent extends Component {
render () { return (<p>Hello</p>)}
}
同样的错误!
我必须错过一些明显的东西......但我没有看到它!
【问题讨论】:
-
您的
C:/[PROJECT_PATH]/src/_base/common/containers/InitPage.js是什么样的?文件抛出错误。 -
正如我所说,它发生在我尝试导入的任何组件上。我编辑了我的消息以澄清并添加测试“AComponent”组件的代码......如果你能看到一些东西......
标签: javascript node.js reactjs ecmascript-6 babeljs