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

Error importing axios (NS8 + WebPack5) #9572

Closed
ipald opened this issue Sep 24, 2021 · 0 comments
Closed

Error importing axios (NS8 + WebPack5) #9572

ipald opened this issue Sep 24, 2021 · 0 comments

Comments

@ipald
Copy link

ipald commented Sep 24, 2021

Hello all, I've some error with webpack porting my application from NS7 to NS8 and enabling webpack 5

Important update after various tries
Reading of this I've tried to rollback to axios@0.20.0, change the import from
import axios from 'axios'
to
import axios from 'axios/dist/axios'
then removing polyfills package, clean and run it again and it works!
So I'm auto-closing the issue

Environment

  • NativeScript 8.1.3
  • NS WebPack: 5.0.0
  • CLI: 8.1.2
  • Android Runtime: 8.1.1
  • iOS Runtime: 8.1.0
  • XCode Version: 12.5.1
  • Plugin(s): axios (any version from 0.20.0+)

Describe the bug
Cannot run/debug if axios is imported. Build succeed but then not run

To Reproduce
Create an empty project (I've tested only with vue), import axios, build fails requesting polyfills.
`...
[1m�[31mERROR�[39m�[22m in �[1m./node_modules/axios/lib/adapters/http.js�[39m�[22m �[1m�[32m7:11-26�[39m�[22m
�[1mModule �[1m�[31mnot found�[39m�[22m�[1m: �[1m�[31mError�[39m�[22m�[1m: Can't resolve 'http' in '/Users/ipald/Projects/mytestapp/node_modules/axios/lib/adapters'
�[1m�[32mDid you mean './http'?�[39m�[22m�[1m
Requests that should resolve in the current directory need to start with './'.
Requests that start with a name are treated as module requests and resolve within module directories (/Users/ipald/Projects/mytestapp/node_modules, node_modules).
If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.

�[1m�[31mBREAKING CHANGE�[39m�[22m�[1m: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "http": require.resolve("stream-http") }'
- install 'stream-http'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "http": false }�[39m�[22m
@ ./node_modules/axios/lib/defaults.js 24:14-40
@ ./node_modules/axios/lib/axios.js 7:15-36
@ ./node_modules/axios/index.js 1:0-39
@ ./app/plugin/data-layer/index.js 1:0-37 20:16-28
@ ./app/plugin/index.js 2:0-37 573:44-53
@ ./app/app.js 11:0-33 85:8-16
...`

I've tried importing node-polyfill-webpack-plugin and configuring it in webpack.config.js with
...webpack.chainWebpack(config => { config.plugin('NodePolyfillPlugin').use(NodePolyfillPlugin) }); ...
then clean and run

ns clean
ns run ios|android

the application is synced with the device but during run fails with

Terminating app due to uncaught exception 'NativeScript encountered a fatal error: Uncaught TypeError: Cannot read property 'env' of undefined at ./node_modules/util/util.js(file: app/webpack:/mytestapp/node_modules/util/util.js:109:11) at __webpack_require__(file: app/webpack:/mytestapp/webpack/bootstrap:24:0) at fn(file: app/webpack:/mytestapp/webpack/runtime/hot module replacement:61:0) at ./node_modules/console-browserify/index.js(file: app/webpack:/mytestapp/node_modules/console-browserify/index.js:2:11) at __webpack_require__(file: app/webpack:/mytestapp/webpack/bootstrap:24:0) at fn(file: app/webpack:/mytestapp/webpack/runtime/hot module replacement:61:0) at ./node_modules/@nativescript/core/profiling/index.js(file:///app/vendor.js:13197:41) at __webpack_require__(file: app/webpack:/mytestapp/webpack/bootstrap:24:0) at fn(file: app/webpack:/mytestapp/webpack/runtime/hot module replacement:61:0) at ./node_modules/@nativescript/core/globals/index.js(file:///app/vendor.js:8256:68) at __webpack_require__(file: app/webpack:/mytestapp/webpack/bootstrap:24:0) at fn(file: app/webpack:/mytestapp/webpack/runtime/hot module replacement:61:0) at ./node_modules/@nativescript/core/inspector_modules.ios.js(file:///app/vendor.js:9956:66) at __webpack_require__(file: app/webpack:/mytestapp/webpack/bootstrap:24:0) at __webpack_exec__(file:///ap<\M-b\M^@\M-&> Successfully synced application org.nativescript.mytestapp on device ****************************************.

Expected behavior
The app runs regularly

Additional context
I've ported another app to NS8 but I didn't migrate webpack to 5 and axios import works. I suspect that the problem is related to polyfills.

@ipald ipald closed this as completed Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant