が定義されていない私は、角度4でAOTを行うにはしばらく帖過ごし、常にこのエラーました: 捕捉されないにReferenceErrorを:angular4のAOTスロー必要がエラー
が定義されていない必要私はjqueryのを使用していますので、私はこのエラーを得ました私のアプリでは、アプリケーションでは、私はこのコードを持っています:私はこれを削除した場合
var jQuery = require('jquery');
jQuery("xxxx").val()
、全体AOTは魅力のように働きました。
私のTSconfig-aot.json:
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"lib": ["es5", "dom"],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
},
"files": [
"src/app/app.module.ts",
"src/main.ts"
],
"angularCompilerOptions": {
"genDir": "aot",
"skipMetadataEmit" : true
}
}
そして、私のロールアップの設定:あなたはその後、AOTはないでしょう、あなたのNG4アプリ内()必要が使用している場合
import rollup from 'rollup'
import nodeResolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs';
import uglify from 'rollup-plugin-uglify'
export default {
entry: 'src/main.js',
dest: 'public/build.js', // output a single application bundle
sourceMap: false,
format: 'iife',
onwarn: function(warning) {
// Skip certain warnings
// should intercept ... but doesn't in some rollup versions
if (warning.code === 'THIS_IS_UNDEFINED') { return; }
// intercepts in some rollup versions
if (warning.indexOf("The 'this' keyword is equivalent to 'undefined'") > -1) { return; }
// console.warn everything else
console.warn(warning.message);
},
plugins: [
nodeResolve({jsnext: true, module: true}),
commonjs({
include: [ 'node_modules/rxjs/**','node_modules/jquery/**']
}),
uglify()
]
}
は、この平均値をい作業?
ありがとうございましたあなたのアドバイスを聞いて願っています。
私はこれを使ってみました: import * as jQuery from 'jquery'; これはrequireと同じように機能し、JITモードではうまくいきました。また、ngcパッケージも問題ありません。
Cannot call a namespace ('jQuery')
src/app/app.component.js (14:8)
12: }
13: AppComponent.prototype.ngOnInit = function() {
14: jQuery('h1').html('New Content');
^
15: };
16: return AppComponent;
これは、更新されたコード:
import * as jQuery from 'jquery';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./scss/app.component.scss']
})
export class AppComponent implements OnInit{
ngOnInit(){
jQuery('h1').html('New Content');
}
}
任意のアイデア私はロールアップを使用する場合でも、入れて、このエラーを持っていますか?
'--module es2015'で' require'を使うべきではありません。これは、TypeScriptのコンパイルエラーを引き起こします。唯一の理由は、正しいものではなく 'var..require'フォームをTypeScriptの' import..require'フォームで使用しているということだけです。それでも、前に述べた理由では正しくありません。 'jquery 'から' import jQuery'を試してください;実行時にjQueryが定義されていないとスローすると 'jquery 'からjQueryとして' import *を試してみてください; –