首页 > 解决方案 > 尝试服务时,Algoliasearch 无法使用 Angular Universal SSR

问题描述

问题

在使用命令成功构建后尝试为我的 Angular Universal 服务时

npm run serve:ssr

带有 Algoliasearch 的 Angular Universal SSR 给了我回应

C:\Users\User\Documents\Project\node_modules\instantsearch.js\es\index.js:2
import algoliasearchHelper from 'algoliasearch-helper';
       ^^^^^^^^^^^^^^^^^^^
SyntaxError: Unexpected identifier
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at algoliasearchProxy__default (C:\Users\User\Documents\Project\node_modules\angular-instantsearch\bundles\angular-instantsearch.umd.js:2:170)
at Object.<anonymous> (C:\Users\User\Documents\Project\node_modules\angular-instantsearch\bundles\angular-instantsearch.umd.js:5:2)
at Module._compile (internal/modules/cjs/loader.js:778:30)

试图

我遵循了https://fireship.io/lessons/angular-universal-firebase/
上的指南, 使用该npm run build:ssr命令时,一切都构建得非常完美。但是,在尝试使用 serve 命令时,它给了我上面的错误。

经过几天的研究,我了解到这可能是一些编译问题。但是,在 GitHub 和众多不同的来源上到处查看后,我找不到任何解决此问题的解决方案。这似乎是一个比 Algolia 和即时搜索更广泛的问题。

我试图将所有软件包更新到最新和特定版本,但它也没有解决我的服务问题。我需要安装 algolia 包,所以我需要任何一种解决方法。

包.json

{
  "name": "operation-angular",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "postinstall": "npm run compile_@agm_core",
    "compile_@agm_core": "babel node_modules/@agm/core -d node_modules/@agm/core --presets @babel/preset-env",
    "dev:ssr": "ng run operation-angular:serve-ssr",
    "serve:ssr": "node dist/operation-angular/server/main.js",
    "build:ssr": "ng build --prod && ng run operation-angular:server:production",
    "prerender": "ng run operation-angular:prerender"
  },
  "private": true,
  "dependencies": {
    "@agm/core": "^1.1.0",
    "@angular/animations": "^9.0.2",
    "@angular/common": "^9.0.2",
    "@angular/compiler": "^9.0.2",
    "@angular/core": "^9.0.2",
    "@angular/forms": "^9.0.2",
    "@angular/http": "^5.2.11",
    "@angular/platform-browser": "^9.0.2",
    "@angular/platform-browser-dynamic": "^9.0.2",
    "@angular/platform-server": "^9.0.2",
    "@angular/router": "^9.0.2",
    "@nguniversal/express-engine": "^9.0.1",
    "@nguniversal/module-map-ngfactory-loader": "^8.2.6",
    "@ngx-meta/core": "^8.0.2",
    "angular-gridster": "^0.13.14",
    "angular-gridster2": "^7.2.0",
    "angular-instantsearch": "^2.2.2",
    "angular-medium-editor": "^4.0.0-alpha",
    "angularfire": "^2.3.0",
    "angularfire2": "^5.4.2",
    "assign-deep": "^1.0.1",
    "bootstrap": "^3.4.1",
    "classlist.js": "^1.1.20150312",
    "core-js": "^2.6.11",
    "dsmorse-gridster": "^0.8.0",
    "express": "^4.15.2",
    "firebase": "^5.11.1",
    "jquery": "^3.4.1",
    "jquery-touchswipe": "^1.6.19",
    "jquery-ui": "^1.12.1",
    "js-sha512": "^0.8.0",
    "medium-editor": "^5.23.3",
    "medium-editor-insert-plugin": "^2.5.1",
    "ngx-image-compress": "^8.0.4",
    "ngx-medium-editor": "^0.4.1",
    "require": "^2.4.20",
    "rxjs": "^6.5.4",
    "rxjs-compat": "^6.5.4",
    "set-value": "^3.0.1",
    "sharp": "^0.23.4",
    "ts-loader": "^6.2.1",
    "tslib": "^1.11.0",
    "update": "^0.7.4",
    "videogular2": "^6.4.0",
    "web-animations-js": "^2.3.2",
    "zone.js": "^0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.803.25",
    "@angular/cli": "^9.0.3",
    "@angular/compiler-cli": "^9.0.2",
    "@angular/language-service": "^9.0.2",
    "@babel/cli": "^7.8.4",
    "@babel/core": "^7.8.4",
    "@babel/preset-env": "^7.8.4",
    "@nguniversal/builders": "^9.0.1",
    "@types/core-js": "^0.9.46",
    "@types/express": "^4.17.0",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "^2.0.8",
    "@types/node": "^13.7.4",
    "codelyzer": "^4.5.0",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "^4.4.1",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.4.3",
    "karma-jasmine": "^1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "^6.0.0",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "3.7.5"
  }
}

标签: angularserver-side-renderingalgoliaangular-universal

解决方案


推荐阅读