Tuesday, November 8, 2016

How to solve "error TS2307: Cannot find module 'angular'" issue in development using sharpeoint page framework

In the WebPart.ts file. I use the import * as angular from angular to reference the external source that pointing to the angular CDN location.

{
  "entries": [
    {
      "entry": "./lib/webparts/itRequest/ItRequestWebPart.js",
      "manifest": "./src/webparts/itRequest/ItRequestWebPart.manifest.json",
      "outputPath": "./dist/it-Request.bundle.js"
    }
  ],
  "externals": {
    "@microsoft/sp-client-base": "node_modules/@microsoft/sp-client-base/dist/sp-client-base.js",
    "@microsoft/sp-client-preview": "node_modules/@microsoft/sp-client-preview/dist/sp-client-preview.js",
    "@microsoft/sp-lodash-subset": "node_modules/@microsoft/sp-lodash-subset/dist/sp-lodash-subset.js",
    "office-ui-fabric-react": "node_modules/office-ui-fabric-react/dist/office-ui-fabric-react.js",
    "react": "node_modules/react/dist/react.min.js",
    "react-dom": "node_modules/react-dom/dist/react-dom.min.js",
    "react-dom/server": "node_modules/react-dom/dist/react-dom-server.min.js",
      "angular": {
            "path": "https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js",
            "globalName": "angular"
          }

  },
  "localizedResources": {
    "itRequestStrings": "webparts/itRequest/loc/{locale}.js"
  }
}

however the syntax error already is shown indicate the type script can not find the angular module.



after i launch the app with Gulp Serve. the same erorr was encounter on the application launch



the root cause of this issue is that the project did not contain the angular TypeScript typing. since it is from the external source. we just need to install the angular TypeScript typing to fix the issue.

here is the steps to add the type script typing to the project.

1. use npm install tsd to install the tsd command (if the tsd is not installed.)

2. run tsd install angular --save to install the angular TypeScript typing. and angularjs will be found under typing folder.







 for more information, please visit the following link. it really save my day...

Use existing JavaScript libraries in SharePoint Framework client-side web parts



How to terminate the process Launched by Gulp Serve

i am quite silly when i start on develpment with gulp. I had to close the CMD Window after i decide to stop the debugging. since the process was running in the window, acutally it is quite simple

just put the curse on CMD Window, then press Control  + C will stop the Gulp sever.


Monday, November 7, 2016

Quick Tips on Development with Sharepoint Page Framework Preview using Visual Code

1. Generated the Sharepoint Page project under the Sharepoint Page Framework

  yo @microsoft/sharepoint

2. Debug the Project with Gulp run time

   Gulp Serve

3. Reference external reources manually
  •    go to the config folder, 
  •    open the config.json file
  •   under the externals section add one entry like  a reference to jquery in the CDN  with key "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"
  • use Import to add the reference the library in WebPart.ts  type script object 
         Import 'jquery'



4. Debug the project with Chrome in Visual Code
  •      installed the Debugger for Chrome extension
  •      run Gulp Serve to start the work process
  •    select Debug from View Menu
  •   click on the Start Button from Debug to launch the Chrome Browser  
 



5.  Load local javascript file. which is located at src\webparts\YourProjectNameFolder
   
open the type script object, add the following line to include the javascript in the load

 public render(): void {
      require('./yourJavascriptFileNameWithoutFileExtension');
  }