Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

require("https") #22

Closed
Daniel-Koenig opened this issue Jul 9, 2018 · 18 comments
Closed

require("https") #22

Daniel-Koenig opened this issue Jul 9, 2018 · 18 comments

Comments

@Daniel-Koenig
Copy link

Hi there,

i am currently using (trying to use) your npm package. Sadly there is a build error when i am using your npm package in my webressource (written in angular 4). The problem there seems to be the 'require("https")' in request.js.

It statens:
ERROR in ./node_modules/xrm-webapi/dist/request.js
Module not found: Error: Can't resolve 'https' in 'MY PATH....\node_modules\xrm-webapi\dist'

It does not seem to get the https reference which is definitly needed, when you use it as a regular npm import. I did not manage to make it work properly, so as i always use your code out of a 'window' i have simply removed the 'reuqire("https")' to make it buildable and workable. This means for me i only can use it from a webressource (which is totally fine, as i only am going to use it in this form), but i can not update this file atm, as it would update this file again. Maybe you can integrate my thought or process in future bug fixes or versions.

If my request is unclear, not enough specified or anything else, please let me know.

Best regards
Daniel

@derekfinlinson
Copy link
Owner

Are you using the latest version? Could you send me a sample of how you're using it? I'm using it just fine in form scripts, node applications and web resources using Vue and Angular 6. Are you using webpack for the build?

@Daniel-Koenig
Copy link
Author

I have used exactly the commands in the description:
npm install --save-dev xrm-webapi (so i guess the version shoud be the newest)
and in the .ts files i use:
import { WebApi, WebApiConfig } from "xrm-webapi";
const apiConfig: WebApiConfig = {
version: "8.2",
url: "XXXX"
};
image

I am using Visual Studio Code and as statened on top i used your commands to import these npms.
For building i am simply using 'npm run build' which works fine anywhere else.

Maybe my problem is, that i dont use Angular 6 which might detect such dependencies out of the box?

@derekfinlinson
Copy link
Owner

"https" is just a standard node module so not sure why it wouldn't be able to find it. You could try installing @types/node although it's not really necessary. It could just be something with angular-cli build process as well.

Upgrading to Angular 6 might be a good idea since I have a project using it that builds fine.

@Daniel-Koenig
Copy link
Author

Daniel-Koenig commented Jul 31, 2018

Sorry for the delayed answer (was on holiday).

It seems to be an userspecific problem. Interestingly the same code works with another user (same settings, and everything though). But i am gonna update my Infos ASAP.

@jordan112
Copy link

jordan112 commented Sep 7, 2018

I'm also experiencing this same problem. I following the same basic steps. I have a fairly vanilla Angular 6 site.

Date: 2018-09-07T15:27:16.555Z
Hash: f0d9a2e6aa7f1a2a0852
Time: 38855ms
chunk {0} runtime.a66f828dca56eeb90e02.js (runtime) 1.05 kB [entry] [rendered]
chunk {1} styles.d67ba1fd166d0b77ab21.css (styles) 56.1 kB [initial] [rendered]
chunk {2} polyfills.2f4a59095805af02bd79.js (polyfills) 59.6 kB [initial] [rendered]
chunk {3} main.c7f9cce592a476fcf988.js (main) 602 kB [initial] [rendered]

ERROR in ./node_modules/xrm-webapi/dist/request.js
Module not found: Error: Can't resolve 'https' in '/Users/<myaccount>/Documents/repos/<my app>/node_modules/xrm-webapi/dist'

Thanks

@derekfinlinson
Copy link
Owner

I found the answer here.

So just add

node: { https: true }

to the file mentioned in that link.

@jordan112
Copy link

Update a file inside of node_modules? Won't that get clobbered with every fresh npm install.

@derekfinlinson
Copy link
Owner

Yes but that appears to be the fix. It's an issue with angular. The better solution would be to separate the node version of xrm-webapi library from the browser version so you only import one or the other. I'll try and come up with a way to do that.

@jordan112
Copy link

Our solution goes through CI builds...so the build server is always going to have a fresh npm install, so that configuration change would never survive.

@derekfinlinson
Copy link
Owner

I won't have a chance to test until later tonight but you could try the answer here. It adds a package that lets you customize the angular-cli webpack config which is what we're doing.

@cpereyra5199
Copy link

Has this been resolved?

@derekfinlinson
Copy link
Owner

@cpereyra5199

Just pushed up a new version that resolves this. To use for angular, you need to import from xrm-webapi/dist/webapi-browser instead of xrm-webapi. I'll update the README to reflect that

@eladnm
Copy link

eladnm commented Feb 27, 2019

@cpereyra5199

Just pushed up a new version that resolves this. To use for angular, you need to import from xrm-webapi/dist/webapi-browser instead of xrm-webapi. I'll update the README to reflect that

  1. i get an error when i try to import both { WebApiConfig, Guid} from 'xrm-webapi/dist/webapi-browser'; they dont have exported member.

  2. when using import { retrieve,WebApi, WebApiConfig } from "xrm-webapi"; i get the https error.

please assist, none of these two options seem to work...
Thanks

@derekfinlinson

@derekfinlinson
Copy link
Owner

derekfinlinson commented Feb 28, 2019

You'll need to import WebApiConfig and Guid from "xrm-webapi" still. It's just the actual api methods that you need to import from "xrm-webapi/dist/webapi-browser". I updated the README to be more clear in that regard

@eladnm
Copy link

eladnm commented Mar 2, 2019

@derekfinlinson
Hi Derek,
Thanks for your help.
following your instructions i still get the error "Module not found: Error: Can't resolve 'https' in '\node_modules\xrm-webapi\dist'"
what else can be done the make this library work?

@cpereyra5199
Copy link

I tried the new update but still got the same error. I ended up using the original fix approach. Adding am extra webpack config and then modifying angular.json like this.

"builder": "@angular-builders/custom-webpack:browser", "options": { "customWebpackConfig": { "path": "./extra-webpack.config.js", "mergeStrategies": { "node": "replace" } },

Then my extra webpack.config looks like this.

module.exports = { node: { https: true } };

@derekfinlinson
Copy link
Owner

I thought I had tested before updating and realized I was incorrect on where to import stuff from. You needed to import everything from the individual files instead of from the xrm-webapi.

After some thought, it seems the most frequently used instance of this library is in the browser so those will be exported from xrm-webapi. I moved the node exports (and https) into a separate file.

The latest version should fix this.

@derekfinlinson
Copy link
Owner

🎉 This issue has been resolved in version 6.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants