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

1.2 use of 'Log' or UrlQueryParameterCollection does not work, fails to bundle

Open pljfdi opened this issue 9 years ago • 6 comments

Category

  • [ ] Question
  • [ ] Typo
  • [x ] Bug
  • [ ] Additional article idea

Expected or Desired Behavior

When adding a Log statement to a webpart, you should be able to gulp bundle the webpart as usual.

Observed Behavior

adding a 'Log' e.g Log.info("HelloWorld", "Here is an informational message.", this.context.serviceScope); will cause the gulp bundle to fail with a webpack error.

below is a the first few lines of an error.


[11:53:56] Error - [webpack] 'dist':
./~/@microsoft/sp-core-library/lib/SPCoreLibraryStrings.resx.js
Module not found: Error: Can't resolve 'resx-strings' in 'C:\code\pfx1.2\node_modules\@microsoft\sp-core-library\lib'
resolve 'resx-strings' in 'C:\code\pfx1.2\node_modules\@microsoft\sp-core-library\lib'
  Parsed request is a module
  using description file: C:\code\pfx1.2\node_modules\@microsoft\sp-core-library\package.json (relative path: ./lib)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: C:\code\pfx1.2\node_modules\@microsoft\sp-core-library\package.json (relative path: ./lib)
    resolve as module
      C:\code\pfx1.2\node_modules\@microsoft\sp-core-library\lib\node_modules doesn't exist or is not a directory
      C:\code\pfx1.2\node_modules\@microsoft\sp-core-library\lib\lib doesn't exist or is not a directory
      C:\code\pfx1.2\node_modules\@microsoft\node_modules doesn't exist or is not a directory
      C:\code\pfx1.2\node_modules\@microsoft\lib doesn't exist or is not a directory
      C:\code\pfx1.2\node_modules\node_modules doesn't exist or is not a directory
      C:\code\pfx1.2\node_modules\lib doesn't exist or is not a directory
      C:\code\node_modules doesn't exist or is not a directory
      C:\code\lib doesn't exist or is not a directory
      C:\node_modules doesn't exist or is not a directory
      C:\lib doesn't exist or is not a directory
      looking for modules in C:\code\pfx1.2\node_modules\@microsoft\sp-core-library\node_modules
        using description file: C:\code\pfx1.2\node_modules\@microsoft\sp-core-library\package.json (relative path: ./node_modules
)

Steps to Reproduce

Using the RC0 1.2, create a new webpart. In any method eg render add a log statement (copied from the Log Working with the Log example) Log.info("HelloWorld", "Here is an informational message.", this.context.serviceScope);

Then try gulp clean;gulp bundle; and it should fail.

Similarly UrlQueryParameterCollection(); Create a new webpart, and in anymethod try the following: var urlParams = new UrlQueryParameterCollection(window.location.href); Then try gulp clean;gulp bundle; and it should fail.

Thanks for your contribution! Sharing is caring.

pljfdi avatar Sep 20 '17 12:09 pljfdi

How are you importing Log? Can you share a sample project?

iclanton avatar Sep 27 '17 00:09 iclanton

package.zip That's an entire project (without node_modules), it really is just a vanilla webpart (HelloWorld with React). Log is imported as in the HelloWorldWebPart.ts import Log from '@microsoft/sp-core-library/lib/log/Log'; and the error occurs during the webpack gulp task.

pljfdi avatar Sep 27 '17 06:09 pljfdi

Oh your issue is that you're trying to import the Log module directly using a file-based import. For SPFx packages, this isn't supported. Everything should be imported from the entry point of the component.

For example, for Log you should say import { Log } from '@microsoft/sp-core-library';.

iclanton avatar Oct 31 '17 23:10 iclanton

Yep. This was caused by Visual Studio Code.

Write a method using something from SPFX (or React for that matter) that you have not imported then press ctrl + . and it will work out what the import should be.

In this case (and several others) it makes the mistake. So over eager tooling, and too much reliance on keyboard shortcuts.


From: Ian Clanton-Thuon [email protected] Sent: 31 October 2017 23:40:25 To: SharePoint/sp-dev-docs Cc: Paul Lawrence; Author Subject: Re: [SharePoint/sp-dev-docs] 1.2 use of 'Log' or UrlQueryParameterCollection does not work, fails to bundle (#870)

Oh your issue is that you're trying to import the Log module directly using a file-based import. For SPFx packages, this isn't supported. Everything should be imported from the entry point of the component.

For example, for Log you should say import { Log } from '@microsoft/sp-core-library';.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/SharePoint/sp-dev-docs/issues/870#issuecomment-340938648, or mute the threadhttps://github.com/notifications/unsubscribe-auth/Ace5Vd-Y-OJacwgd8dqAG2H6dH_LoBcKks5sx6_pgaJpZM4PdxNa.

pljfdi avatar Nov 01 '17 08:11 pljfdi

Interesting. I didn't know about that shortcut.

For SPFx dependencies, everything should be imported from the root of the package to make sure dependencies get linked together correctly.

iclanton avatar Nov 03 '17 22:11 iclanton

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 29 '20 00:01 msft-github-bot