无法获取在IE11上运行的jhipster(6.3.1)生成的应用程序

时间:2019-10-01 10:33:07

标签: angular internet-explorer-11 jhipster

我正在尝试使JHipster 6.3.1生成的应用程序在IE 11中运行,但是继续出现一个错误。根据我在polyfill.ts中使用的导入方式,我会得到从“符号”未定义”到普通的“语法错误”,有时甚至根本没有特定错误的任何信息,只有带有通用JHipster的页面

  

发生了错误:-(

我尝试了polyfillstsconfig.json设置的不同组合。我已经按照角度8文档安装了推荐的polyfills,但是似乎jhipsters angular != standard angular以及所有与angular 8有关的纯IE11文档都没有帮助。

我知道IE 11不再支持JHipster,但是由于Angular有使用polyfills和差分加载使其工作的特定说明,我希望(假设)它将一个相当简单的解决方法。

2 个答案:

答案 0 :(得分:1)

正如我所说的here,我设法通过以下方式进行操作。

首先,添加以下package.json个依赖项:@babel/core@babel/preset-envbabel-loader

yarn add @babel/core @babel/preset-env babel-loader --exact --dev

(经过以下版本测试:

    "@babel/core": "7.6.4",
    "@babel/preset-env": "7.6.3",
    "babel-loader": "8.0.6",

现在在src/main/webapp/app/polyfills.ts的顶部添加以下行:

import 'core-js/stable';
import 'regenerator-runtime/runtime';

webpack/webpack.common.js之后

            {
                test: /manifest.webapp$/,
                loader: 'file-loader',
                options: {
                    name: 'manifest.webapp'
                }
            },

添加以下几行:

            {
                test: /\.js/,
                use: {
                  loader: 'babel-loader',
                  options: {
                    "presets": [
                      [
                        "@babel/preset-env",
                        {
                          "targets": {
                            "firefox": "60",
                            "ie": "11"
                          },
                          "useBuiltIns": "entry",
                          "corejs": 3
                        }
                      ]
                    ]
                  }
                },
                exclude: /@babel(?:\/|\\{1,2})runtime|core-js/,
              },

最后,在targetes5中将tsconfig.json更改为tsconfig-aot.json

这是我的完整测试:

sudo rm -rf /dev/shm/myproject
cd /dev/shm/
mkdir myproject
cd myproject
mkdir /dev/shm/m2cache /dev/shm/yarncache
sudo tee myproject.jdl <<EOF
application {
    config {
        baseName MyProject
        clientPackageManager yarn
        jhiPrefix mp
        enableTranslation false
        languages [fr]
        nativeLanguage fr
        packageName com.mycompany.myproject
        prodDatabaseType postgresql
        skipUserManagement true
    }
    entities *
}

entity MyEntity {
    label String
}
EOF
JHIPSTER_VERSION=v6.3.1
sudo chown -R 1000:1000 . /dev/shm/m2cache /dev/shm/yarncache
docker run -it --rm --name jhipster -v "$(pwd):/home/jhipster/app" -v /dev/shm/m2cache:/home/jhipster/.m2 -v /dev/shm/yarncache:/home/jhipster/.cache/yarn -v "$HOME/.gitconfig:/home/jhipster/.gitconfig:ro" jhipster/jhipster:$JHIPSTER_VERSION jhipster import-jdl ./myproject.jdl --force

# WAIT FOR THE APPLICATION TO BE GENERATED

docker run -it --rm --name jhipster -v "$(pwd):/home/jhipster/app" -v /dev/shm/m2cache:/home/jhipster/.m2 -v /dev/shm/yarncache:/home/jhipster/.cache/yarn -p 9000:9000 -p 8080:8080 jhipster/jhipster:$JHIPSTER_VERSION yarn add @babel/core @babel/preset-env babel-loader --exact --dev

# WAIT FOR THE YARN COMMAND TO END

echo "
import 'core-js/stable';
import 'regenerator-runtime/runtime';

$(cat src/main/webapp/app/polyfills.ts)
" | sudo -u '#1000' tee src/main/webapp/app/polyfills.ts

cat > /dev/shm/webpack.patch <<EOF
            {
                test: /\.js/,
                use: {
                  loader: 'babel-loader',
                  options: {
                    "presets": [
                      [
                        "@babel/preset-env",
                        {
                          "targets": {
                            "firefox": "60",
                            "ie": "11"
                          },
                          "useBuiltIns": "entry",
                          "corejs": 3
                        }
                      ]
                    ]
                  }
                },
                exclude: /@babel(?:\/|\\{1,2})runtime|core-js/,
            },
EOF
sudo -u '#1000' sed -i $'/Ignore warnings about System.import in Angular/{e cat /dev/shm/webpack.patch\n}' webpack/webpack.common.js

for FILE in tsconfig.json tsconfig-aot.json; do
  sudo -u '#1000' sed -i 's/"target": "es6"/"target": "es5"/' $FILE
done

docker run -it --rm --name jhipster -v "$(pwd):/home/jhipster/app" -v /dev/shm/m2cache:/home/jhipster/.m2 -v /dev/shm/yarncache:/home/jhipster/.cache/yarn -p 9000:9000 -p 8080:8080 jhipster/jhipster:$JHIPSTER_VERSION bash -c "./mvnw & yarn start --host 0.0.0.0"

感谢https://www.thebasement.be/working-with-babel-7-and-webpack/https://babeljs.io/docs/en/usagehttps://github.com/zloirock/core-js/issues/514#issuecomment-523524472的提示!

答案 1 :(得分:0)

我设法使其正常运行。我所做的是我使用较旧的Angular的ng CLI生成了Angular应用程序。我比较了tsconfig.jsonpackage.jsonpolyfills.ts,并使用了JHipster生成的“较旧”设置。这给了我以下变化:

package.json中降低的版本:

  • core-js3.1.3^2.4.1
  • zone-js0.9.1^0.7.2

tsfconfig.json中:

    "target": "es5",
    "module": "es6",

    "lib": ["es6", "dom"],

最后是polyfills.ts

    import 'core-js/es6/symbol';
    import 'core-js/es6/object';
    import 'core-js/es6/function';
    import 'core-js/es6/parse-int';
    import 'core-js/es6/parse-float';
    import 'core-js/es6/number';
    import 'core-js/es6/math';
    import 'core-js/es6/string';
    import 'core-js/es6/date';
    import 'core-js/es6/array';
    import 'core-js/es6/regexp';
    import 'core-js/es6/map';
    import 'core-js/es6/set';
    import 'core-js/es6/reflect';
    import 'core-js/es7/reflect';
    import 'core-js/es7/array';
    import 'core-js/es7/object';
    import 'zone.js/dist/zone.js';
    require('../manifest.webapp');

这些更改使我在IE11中可以正常工作,但仅使用prod构建。