我弹出了一个Angular Cli项目,并尝试将Angular Universal集成到其中。我已经把项目捆绑了应该。问题是当我运行“node dist / server.js”时,我收到Unexpected Token
错误。
完整错误:
/Users/brandon.baker/Documents/Sites/brand-angular-seed/dist/server.js:405665
module.exports = ./../node_modules/webpack/buildin/module.js;
^
SyntaxError: Unexpected token .
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:599:28)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Function.Module.runMain (module.js:676:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
Webpack配置:
// Work around for https://github.com/angular/angular-cli/issues/7200
const path = require('path');
const webpack = require('webpack');
module.exports = {
entry: {
// This is our Express server for Dynamic universal
server: './server.ts',
// This is an example of Static prerendering (generative)
prerender: './prerender.ts'
},
target: 'node',
resolve: { extensions: ['.ts', '.js'] },
// Make sure we include all node_modules etc
externals: [
/(node_modules|main\..*\.js)/,
{
'sqlite3': 'sqlite3',
'mariasql': 'mariasql',
'mssql': 'mssql',
'mysql': 'mysql',
'oracle': 'oracle',
'strong-oracle': 'strong-oracle',
'oracledb': 'oracledb',
'pg': 'pg',
'pg-query-stream': 'pg-query-stream',
'hiredis': 'hiredis',
'redis-parser': 'redis-parser',
'fsevents': 'fsevents',
'node-gyp': 'node-gyp'
}
],
output: {
// Puts the output at the root of the dist folder
path: path.join(__dirname, 'dist'),
filename: '[name].js'
},
module: {
rules: [
{ test: /\.ts$/, loader: 'ts-loader', exclude: /node_modules/ }
]
},
plugins: [
new webpack.ContextReplacementPlugin(
// fixes WARNING Critical dependency: the request of a dependency is an expression
/(.+)?angular(\\|\/)core(.+)?/,
path.join(__dirname, 'src'), // location of your src
{} // a map of your routes
),
new webpack.ContextReplacementPlugin(
// fixes WARNING Critical dependency: the request of a dependency is an expression
/(.+)?express(\\|\/)(.+)?/,
path.join(__dirname, 'src'),
{}
)
]
}
也许解决方案很明确,我只是不知道为什么这个问题无法解决。它应该不是在寻找node_modules文件夹,对吗?
答案 0 :(得分:1)
我有同样的问题。 就我而言,问题的原因是纱线工作区。
将与Webpack相关的软件包包含到<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="extraFileTemplate">
<div class="controls controls-row">
<input class="span3" placeholder="Select File" type="file" name="file_name">
<input type=button value="clear" name="cler">
</div>
</div>
<div id="container"></div>
<a href="#" id="addRow"><i class="icon-plus-sign icon-white"></i> Add another file</p></a>
中解决了该问题。
nohoist