sp-dev-docs icon indicating copy to clipboard operation
sp-dev-docs copied to clipboard

sp-module-loader loadCss broken in Drop 6

Open jaredbuttars opened this issue 10 years ago • 3 comments

Category

  • [ ] Question
  • [ ] Typo
  • [x] Bug
  • [ ] Enhancement / Suggestion
  • [ ] Additional article idea

Expected or Desired Behavior

This code worked fine in drop 5, I expected it to also work in Drop 6

import importableModuleLoader from '@microsoft/sp-module-loader';
importableModuleLoader.loadCss('URLToCSS');

Observed Behavior

Running Gulp with Drop 6 generates a several hundred line error (truncated)

[09:58:33] Error - [webpack] 'dist':
./~/@microsoft/sp-module-loader/lib/SystemJsWrapper.js
Module not found: Error: Cannot resolve module 'raw-script' in D:\Projects\WIF\webparts\node_modules\@microsoft\sp-module-loader\lib
resolve module raw-script in D:\Projects\WIF\webparts\node_modules\@microsoft\sp-module-loader\lib
  looking for modules in D:\Projects\WIF\webparts\node_modules\@microsoft\sp-build-core-tasks\node_modules
    module variation @microsoft/loader-raw-script
      D:\Projects\WIF\webparts\node_modules\@microsoft\sp-build-core-tasks\node_modules\@microsoft doesn't exist (module as directory)
    module variation raw-script-webpack-loader
      D:\Projects\WIF\webparts\node_modules\@microsoft\sp-build-core-tasks\node_modules\raw-script-webpack-loader doesn't exist (module as directory)
      resolve 'file' raw-script-webpack-loader in D:\Projects\WIF\webparts\node_modules\@microsoft\sp-build-core-tasks\node_modules
        resolve file
          D:\Projects\WIF\webparts\node_modules\@microsoft\sp-build-core-tasks\node_modules\raw-script-webpack-loader.webpack-loader.js doesn't exist
          D:\Projects\WIF\webparts\node_modules\@microsoft\sp-build-core-tasks\node_modules\raw-script-webpack-loader doesn't exist
          D:\Projects\WIF\webparts\node_modules\@microsoft\sp-build-core-tasks\node_modules\raw-script-webpack-loader.web-loader.js doesn't exist
          D:\Projects\WIF\webparts\node_modules\@microsoft\sp-build-core-tasks\node_modules\raw-script-webpack-loader.loader.js doesn't exist
          D:\Projects\WIF\webparts\node_modules\@microsoft\sp-build-core-tasks\node_modules\raw-script-webpack-loader.js doesn't exist
    module variation raw-script-web-loader

Steps to Reproduce

Use sp-module-loader to load CSS and run Gulp using Drop 6

jaredbuttars avatar Nov 26 '16 17:11 jaredbuttars

I'm guessing the module loader isn't excluded in your config/config.json file, so your project is trying to bundle it, which won't work. Can you take a look at your config.json file and confirm that you have a node like the first one under externals below:

{
  "entries": [
    {
      "entry": "./lib/webparts/helloWorld/HelloWorldWebPart.js",
      "manifest": "./src/webparts/helloWorld/HelloWorldWebPart.manifest.json",
      "outputPath": "./dist/hello-world.bundle.js"
    }
  ],
  "externals": {
    // You need this line
    "@microsoft/sp-module-loader": "node_modules/@microsoft/sp-module-loader/dist/sp-module-loader.js",

    "@microsoft/sp-client-base": "node_modules/@microsoft/sp-client-base/dist/sp-client-base.js",
    "@microsoft/sp-webpart-base": "node_modules/@microsoft/sp-webpart-base/dist/sp-webpart-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"
  },
  "localizedResources": {
    "helloWorldStrings": "webparts/helloWorld/loc/{locale}.js"
  }
}

iclanton avatar Nov 26 '16 21:11 iclanton

@iclanton Thanks that was the problem.

jaredbuttars avatar Nov 27 '16 00:11 jaredbuttars

Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues

msft-github-bot avatar Jan 30 '20 00:01 msft-github-bot