storybookjs / storybook

Storybook is the industry standard workshop for building, documenting, and testing UI components in isolation
https://storybook.js.org
MIT License
84.7k stars 9.33k forks source link

fn.bind is not a function at newTrustedFunctionForJIT - Angular 11 #13722

Closed ChazUK closed 3 years ago

ChazUK commented 3 years ago

After creating a new Angular 11 project using @angular/cli and then running npx sb init to add Storybook I am running into the following error.

fn.bind is not a function
TypeError: fn.bind is not a function
    at newTrustedFunctionForJIT (http://localhost:6006/vendors~main.2a4ceef72b0b8e6191d9.bundle.js:12552:15)
    at JitEvaluator.evaluateCode (http://localhost:6006/vendors~main.2a4ceef72b0b8e6191d9.bundle.js:12616:29)
    at JitEvaluator.evaluateStatements (http://localhost:6006/vendors~main.2a4ceef72b0b8e6191d9.bundle.js:12590:21)
    at JitCompiler._interpretOrJit (http://localhost:6006/vendors~main.2a4ceef72b0b8e6191d9.bundle.js:34717:39)
    at JitCompiler._compileTemplate (http://localhost:6006/vendors~main.2a4ceef72b0b8e6191d9.bundle.js:34689:33)
    at http://localhost:6006/vendors~main.2a4ceef72b0b8e6191d9.bundle.js:34631:46
    at Set.forEach (<anonymous>)
    at JitCompiler._compileComponents (http://localhost:6006/vendors~main.2a4ceef72b0b8e6191d9.bundle.js:34631:19)
    at http://localhost:6006/vendors~main.2a4ceef72b0b8e6191d9.bundle.js:34544:18
    at Object.then (http://localhost:6006/vendors~main.2a4ceef72b0b8e6191d9.bundle.js:8209:52)

I tried with Angular 10 and it all works smoothly, perhaps it has something to do with Ivy?

npx sb info

Environment Info:

  System:
    OS: macOS 10.15.7
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Binaries:
    Node: 14.14.0 - /usr/local/bin/node
    Yarn: 1.22.10 - ~/.global-npm/bin/yarn
    npm: 6.14.10 - ~/.global-npm/bin/npm
  Browsers:
    Chrome: 83.0.4103.61
    Firefox: 68.6.1
    Safari: 13.1.3
  npmPackages:
    @storybook/addon-actions: ^6.1.15 => 6.1.15 
    @storybook/addon-essentials: ^6.1.15 => 6.1.15 
    @storybook/addon-links: ^6.1.15 => 6.1.15 
    @storybook/angular: ^6.1.15 => 6.1.15 

ng version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/

Angular CLI: 11.1.1
Node: 14.14.0
OS: darwin x64

Angular: 11.1.0
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1101.1
@angular-devkit/build-angular   0.1101.1
@angular-devkit/core            11.1.1
@angular-devkit/schematics      11.1.1
@angular/cli                    11.1.1
@schematics/angular             11.1.1
@schematics/update              0.1101.1
rxjs                            6.6.3
typescript                      4.1.3

package.json

{
  "name": "angular11-storybook",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "docs:json": "compodoc -p ./tsconfig.json -e json -d .",
    "storybook": "npm run docs:json && start-storybook -p 6006",
    "build-storybook": "npm run docs:json && build-storybook"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~11.1.0",
    "@angular/common": "~11.1.0",
    "@angular/compiler": "~11.1.0",
    "@angular/core": "~11.1.0",
    "@angular/forms": "~11.1.0",
    "@angular/platform-browser": "~11.1.0",
    "@angular/platform-browser-dynamic": "~11.1.0",
    "@angular/router": "~11.1.0",
    "rxjs": "~6.6.0",
    "tslib": "^2.0.0",
    "zone.js": "~0.11.3"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.1101.1",
    "@angular/cli": "~11.1.1",
    "@angular/compiler-cli": "~11.1.0",
    "@babel/core": "^7.12.10",
    "@compodoc/compodoc": "^1.1.11",
    "@storybook/addon-actions": "^6.1.15",
    "@storybook/addon-essentials": "^6.1.15",
    "@storybook/addon-links": "^6.1.15",
    "@storybook/angular": "^6.1.15",
    "@types/jasmine": "~3.6.0",
    "@types/node": "^12.11.1",
    "babel-loader": "^8.2.2",
    "codelyzer": "^6.0.0",
    "jasmine-core": "~3.6.0",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~5.2.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.0.3",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "protractor": "~7.0.0",
    "ts-node": "~8.3.0",
    "tslint": "~6.1.0",
    "typescript": "~4.1.2"
  }
}
ChazUK commented 3 years ago

AOT is set to true in angular.json and I have also tried adding "postinstall": "ngcc", to the scripts and re-ran npm install but the error is still coming up

daniloff200 commented 3 years ago

hey! I saw the old issue sometime ago https://github.com/angular/angular/issues/40507 and it can be related maybe? In this case it was tests failure because of Chrome version, but, maybe will help you too

ChazUK commented 3 years ago

@daniloff200 thank you so much, this is the exact issue. I don't know why that hasn't come up when I search for it!

daniloff200 commented 3 years ago

yeah, I also stucked in this one today, and solution above helped me too :)