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

package.json browser field has no effect (bundling Axios) #427

Closed
trungtin opened this issue Sep 26, 2022 · 4 comments · Fixed by #428
Closed

package.json browser field has no effect (bundling Axios) #427

trungtin opened this issue Sep 26, 2022 · 4 comments · Fixed by #428
Labels
kind: bug Something isn't working properly kind: regression Specific type of bug -- past behavior that worked is now broken scope: integration Related to an integration, not necessarily to core (but could influence core) solution: needs test This issue requires creating a test to assuredly close out solution: workaround available There is a workaround available for this issue

Comments

@trungtin
Copy link

trungtin commented Sep 26, 2022

Troubleshooting

  1. Does tsc have the same output? If so, please explain why this is incorrect behavior
    yes

  2. Does your Rollup plugin order match this plugin's compatibility? If not, please elaborate
    yes

  3. Can you create a minimal example that reproduces this behavior? Preferably, use this environment for your reproduction
    https://stackblitz.com/edit/rpt2-repro-xabeaq?file=rollup.config.js

What happens and why it is incorrect

the Axios package has this field browser set in package.json that map

...adapters/http.js -> ...adapters/xhr.js

the @rollup/plugin-node-resolve plugin correctly resolves this file when bundling for browser. When add typescript with this plugin (or @rollup/plugin-typescript), the adapters/http.js file is included in the bundle. How to let this plugin know that the bundle is for the browser?

Environment

browser bundle

Versions

  System:
    OS: Linux 5.0 undefined
    CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 7.17.0 - /usr/local/bin/npm
  npmPackages:
    rollup: ^2.75.6 => 2.79.1 
    rollup-plugin-typescript2: ^0.33.0 => 0.33.0 
    typescript: ^4.7.3 => 4.8.3 

import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from 'rollup-plugin-typescript2';

export default {
  input: './src/index.ts',
  output: {
    file: './dist/index.js',
    format: 'iife',
    exports: 'named',
  },
  plugins: [
    resolve({
      browser: true,
    }),
    commonjs(),
    typescript({
      verbosity: 3,
      clean: true,
    }),
  ],
};

tsconfig.json

:
{
  // https://github.com/agilgur5/tsconfig
  "extends": "@agilgur5/tsconfig/src/tsconfig.library.json",
  // exclude node_modules (the default), dist dir, coverage dir, and example for now
  "exclude": ["node_modules/", "dist/", "coverage/", "example/"],
  // all TS files in the src/ dir
  "include": ["src/**/*"],
  // see https://www.typescriptlang.org/tsconfig to better understand tsconfigs
  "compilerOptions": {
    // output to dist/ dir
    "outDir": "./dist/",
    // match output dir to input dir. e.g. dist/index instead of dist/src/index
    "rootDir": "./src",
    "noImplicitAny": false
  }
}

package.json

:

plugin output with verbosity 3

:
./src/index.ts → ./dist/index.js...
rpt2: built-in options overrides: {
    "noEmitHelpers": false,
    "importHelpers": true,
    "noResolve": false,
    "noEmit": false,
    "noEmitOnError": false,
    "inlineSourceMap": false,
    "outDir": "/home/projects/rpt2-repro-xabeaq/node_modules/.cache/rollup-plugin-typescript2/placeholder",
    "moduleResolution": 2,
    "allowNonTsExtensions": true,
    "module": 5
}
rpt2: parsed tsconfig: {
    "options": {
        "strict": true,
        "allowUnusedLabels": false,
        "allowUnreachableCode": false,
        "exactOptionalPropertyTypes": true,
        "noFallthroughCasesInSwitch": true,
        "noImplicitOverride": true,
        "noImplicitReturns": true,
        "noPropertyAccessFromIndexSignature": true,
        "noUncheckedIndexedAccess": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "importsNotUsedAsValues": 2,
        "checkJs": true,
        "esModuleInterop": true,
        "skipLibCheck": true,
        "forceConsistentCasingInFileNames": true,
        "outDir": "/home/projects/rpt2-repro-xabeaq/node_modules/.cache/rollup-plugin-typescript2/placeholder",
        "sourceMap": true,
        "moduleResolution": 2,
        "resolveJsonModule": true,
        "jsx": 2,
        "noEmit": false,
        "declaration": true,
        "declarationMap": true,
        "rootDir": "/home/projects/rpt2-repro-xabeaq/src",
        "noImplicitAny": false,
        "configFilePath": "/home/projects/rpt2-repro-xabeaq/tsconfig.json",
        "noEmitHelpers": false,
        "importHelpers": true,
        "noResolve": false,
        "noEmitOnError": false,
        "inlineSourceMap": false,
        "allowNonTsExtensions": true,
        "module": 5
    },
    "fileNames": [
        "/home/projects/rpt2-repro-xabeaq/src/index.ts"
    ],
    "typeAcquisition": {
        "enable": false,
        "include": [],
        "exclude": []
    },
    "raw": {
        "extends": "@agilgur5/tsconfig/src/tsconfig.library.json",
        "exclude": [
            "node_modules/",
            "dist/",
            "coverage/",
            "example/"
        ],
        "include": [
            "src/**/*"
        ],
        "compilerOptions": {
            "outDir": "./dist/",
            "rootDir": "./src",
            "noImplicitAny": false
        },
        "compileOnSave": false
    },
    "errors": [],
    "wildcardDirectories": {
        "/home/projects/rpt2-repro-xabeaq/src": 1
    },
    "compileOnSave": false
}
rpt2: typescript version: 4.8.3
rpt2: tslib version: 2.4.0
rpt2: rollup version: 2.79.1
rpt2: rollup-plugin-typescript2 version: 0.33.0
rpt2: plugin options:
{
    "check": true,
    "verbosity": 3,
    "clean": true,
    "cacheRoot": "/home/projects/rpt2-repro-xabeaq/node_modules/.cache/rollup-plugin-typescript2",
    "include": [
        "*.ts+(|x)",
        "**/*.ts+(|x)"
    ],
    "exclude": [
        "*.d.ts",
        "**/*.d.ts"
    ],
    "abortOnError": true,
    "rollupCommonJSResolveHack": false,
    "useTsconfigDeclarationDir": false,
    "tsconfigOverride": {},
    "transformers": [],
    "tsconfigDefaults": {},
    "objectHashIgnoreUnknownHack": false,
    "cwd": "/home/projects/rpt2-repro-xabeaq",
    "typescript": "version 4.8.3"
}
rpt2: rollup config:
{
    "external": [],
    "input": "./src/index.ts",
    "plugins": [
        {
            "name": "commonjs--resolver"
        },
        {
            "name": "node-resolve",
            "version": "14.1.0",
            "resolveId": {
                "order": "post"
            }
        },
        {
            "name": "commonjs",
            "version": "22.0.2"
        },
        {
            "name": "rpt2"
        },
        {
            "name": "stdin"
        }
    ],
    "output": [
        {
            "exports": "named",
            "file": "./dist/index.js",
            "format": "iife",
            "plugins": []
        }
    ]
}
rpt2: tsconfig path: /home/projects/rpt2-repro-xabeaq/tsconfig.json
rpt2: included:
[
    "*.ts+(|x)",
    "**/*.ts+(|x)"
]
rpt2: excluded:
[
    "*.d.ts",
    "**/*.d.ts"
]
rpt2: transpiling '/home/projects/rpt2-repro-xabeaq/src/index.ts'
rpt2: generated declarations for '/home/projects/rpt2-repro-xabeaq/src/index.ts'
rpt2: resolving './lib/axios' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/index.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/axios.js'
rpt2: resolving './utils' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/axios.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/utils.js'
rpt2: resolving './helpers/bind' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/axios.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/helpers/bind.js'
rpt2: resolving './core/Axios' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/axios.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/Axios.js'
rpt2: resolving './core/mergeConfig' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/axios.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/mergeConfig.js'
rpt2: resolving './defaults' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/axios.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/defaults/index.js'
rpt2: resolving './cancel/CanceledError' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/axios.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/cancel/CanceledError.js'
rpt2: resolving './cancel/CancelToken' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/axios.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/cancel/CancelToken.js'
rpt2: resolving './cancel/isCancel' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/axios.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/cancel/isCancel.js'
rpt2: resolving './env/data' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/axios.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/env/data.js'
rpt2: resolving './helpers/toFormData' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/axios.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/helpers/toFormData.js'
rpt2: resolving '../lib/core/AxiosError' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/axios.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/AxiosError.js'
rpt2: resolving './helpers/spread' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/axios.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/helpers/spread.js'
rpt2: resolving './helpers/isAxiosError' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/axios.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/helpers/isAxiosError.js'
rpt2: resolving './helpers/bind' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/utils.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/helpers/bind.js'
rpt2: resolving './../utils' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/Axios.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/utils.js'
rpt2: resolving '../helpers/buildURL' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/Axios.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/helpers/buildURL.js'
rpt2: resolving './InterceptorManager' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/Axios.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/InterceptorManager.js'
rpt2: resolving './dispatchRequest' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/Axios.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/dispatchRequest.js'
rpt2: resolving './mergeConfig' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/Axios.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/mergeConfig.js'
rpt2: resolving './buildFullPath' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/Axios.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/buildFullPath.js'
rpt2: resolving '../helpers/validator' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/Axios.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/helpers/validator.js'
rpt2: resolving '../utils' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/mergeConfig.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/utils.js'
rpt2: resolving '../utils' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/defaults/index.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/utils.js'
rpt2: resolving '../helpers/normalizeHeaderName' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/defaults/index.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/helpers/normalizeHeaderName.js'
rpt2: resolving '../core/AxiosError' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/defaults/index.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/AxiosError.js'
rpt2: resolving './transitional' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/defaults/index.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/defaults/transitional.js'
rpt2: resolving '../helpers/toFormData' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/defaults/index.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/helpers/toFormData.js'
rpt2: resolving '../adapters/xhr' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/defaults/index.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/adapters/xhr.js'
rpt2: resolving '../adapters/http' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/defaults/index.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/adapters/http.js'
rpt2: resolving './env/FormData' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/defaults/index.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/defaults/env/FormData.js'
rpt2: resolving '../core/AxiosError' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/cancel/CanceledError.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/AxiosError.js'
rpt2: resolving '../utils' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/cancel/CanceledError.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/utils.js'
rpt2: resolving './CanceledError' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/cancel/CancelToken.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/cancel/CanceledError.js'
rpt2: resolving '../utils' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/helpers/toFormData.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/utils.js'
rpt2: resolving '../utils' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/AxiosError.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/utils.js'
rpt2: resolving './../utils' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/helpers/isAxiosError.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/utils.js'
rpt2: resolving './../utils' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/helpers/buildURL.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/utils.js'
rpt2: resolving './../utils' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/InterceptorManager.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/utils.js'
rpt2: resolving './../utils' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/dispatchRequest.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/utils.js'
rpt2: resolving './transformData' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/dispatchRequest.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/transformData.js'
rpt2: resolving '../cancel/isCancel' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/dispatchRequest.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/cancel/isCancel.js'
rpt2: resolving '../defaults' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/dispatchRequest.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/defaults/index.js'
rpt2: resolving '../cancel/CanceledError' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/dispatchRequest.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/cancel/CanceledError.js'
rpt2: resolving '../helpers/isAbsoluteURL' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/buildFullPath.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/helpers/isAbsoluteURL.js'
rpt2: resolving '../helpers/combineURLs' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/buildFullPath.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/helpers/combineURLs.js'
rpt2: resolving '../env/data' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/helpers/validator.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/env/data.js'
rpt2: resolving '../core/AxiosError' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/helpers/validator.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/AxiosError.js'
rpt2: resolving '../utils' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/helpers/normalizeHeaderName.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/utils.js'
rpt2: resolving './../utils' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/adapters/xhr.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/utils.js'
rpt2: resolving './../core/settle' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/adapters/xhr.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/settle.js'
rpt2: resolving './../helpers/cookies' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/adapters/xhr.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/helpers/cookies.js'
rpt2: resolving './../helpers/buildURL' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/adapters/xhr.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/helpers/buildURL.js'
rpt2: resolving '../core/buildFullPath' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/adapters/xhr.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/buildFullPath.js'
rpt2: resolving './../helpers/parseHeaders' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/adapters/xhr.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/helpers/parseHeaders.js'
rpt2: resolving './../helpers/isURLSameOrigin' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/adapters/xhr.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/helpers/isURLSameOrigin.js'
rpt2: resolving '../defaults/transitional' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/adapters/xhr.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/defaults/transitional.js'
rpt2: resolving '../core/AxiosError' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/adapters/xhr.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/AxiosError.js'
rpt2: resolving '../cancel/CanceledError' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/adapters/xhr.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/cancel/CanceledError.js'
rpt2: resolving '../helpers/parseProtocol' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/adapters/xhr.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/helpers/parseProtocol.js'
rpt2: resolving './../utils' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/adapters/http.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/utils.js'
rpt2: resolving './../core/settle' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/adapters/http.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/settle.js'
rpt2: resolving '../core/buildFullPath' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/adapters/http.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/buildFullPath.js'
rpt2: resolving './../helpers/buildURL' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/adapters/http.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/helpers/buildURL.js'
rpt2: resolving 'follow-redirects' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/adapters/http.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/follow-redirects/index.js'
rpt2: resolving './../env/data' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/adapters/http.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/env/data.js'
rpt2: resolving '../defaults/transitional' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/adapters/http.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/defaults/transitional.js'
rpt2: resolving '../core/AxiosError' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/adapters/http.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/AxiosError.js'
rpt2: resolving '../cancel/CanceledError' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/adapters/http.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/cancel/CanceledError.js'
rpt2: resolving './../utils' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/transformData.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/utils.js'
rpt2: resolving '../defaults' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/transformData.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/defaults/index.js'
rpt2: resolving './AxiosError' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/settle.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/core/AxiosError.js'
rpt2: resolving './../utils' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/helpers/cookies.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/utils.js'
rpt2: resolving './../utils' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/helpers/parseHeaders.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/utils.js'
rpt2: resolving './../utils' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/helpers/isURLSameOrigin.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/utils.js'
rpt2: resolving './debug' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/follow-redirects/index.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/follow-redirects/debug.js'
rpt2: resolving '/home/projects/rpt2-repro-xabeaq/node_modules/form-data/lib/browser.js' imported by '/home/projects/rpt2-repro-xabeaq/node_modules/axios/lib/defaults/env/FormData.js'
rpt2:     to '/home/projects/rpt2-repro-xabeaq/node_modules/form-data/lib/browser.js'
(!) Missing shims for Node.js built-ins
Creating a browser bundle that depends on "http", "https", "url", "stream", "assert" and "zlib". You might need to include https://github.com/FredKSchott/rollup-plugin-polyfill-node
(!) If you do not supply "output.name", you may not be able to access the exports of an IIFE bundle.
rpt2: generating target 1
rpt2: emitting declarations for '/home/projects/rpt2-repro-xabeaq/src/index.ts' to 'index.d.ts'
rpt2: emitting declarations for '/home/projects/rpt2-repro-xabeaq/src/index.ts' to 'index.d.ts.map'
(!) Missing global variable names
Use output.globals to specify browser global variable names corresponding to external modules
http (guessing 'require$$1')
https (guessing 'require$$2')
url (guessing 'require$$0')
stream (guessing 'require$$3')
assert (guessing 'require$$4')
zlib (guessing 'require$$8')
created ./dist/index.js in 671ms
@agilgur5 agilgur5 changed the title package.json browser field have no effect when bundle for browser (bundle Axios) package.json browser field has no effect (bundling Axios) Sep 26, 2022
@agilgur5
Copy link
Collaborator

agilgur5 commented Sep 26, 2022

exclude node_modules

So normally node_modules are placed in Rollup's externals, but as you're outputting an IIFE, your Rollup plugins are trying to resolve this.

rpt2 doesn't implement its own resolution algorithm, it just uses TypeScript's resolution, which is why the result is the same with tsc. Per your opening:

  1. Does tsc have the same output? If so, please explain why this is incorrect behavior
    yes

Now, normally, rpt2 only includes TS files, so axios (or most node_modules) should be excluded as they're distributed in JS, not TS.

You can force this exclusion by adding exclude: ['**/node_modules/**/*'], to your rpt2 config, as in:

   typescript({
      verbosity: 3,
      clean: true,
      exclude: ['**/node_modules/**/*'],
    }),

And you can see this working in my example here: https://stackblitz.com/edit/rpt2-issue-427?file=rollup.config.js

Regression in rpt2 0.33.0, downgrade for now

Important Note: this works in rpt2 0.32, which is what I'm using in my example above.
In fact, in 0.32, you actually don't need the exclude at all. It works with zero config.

So for now, I recommend downgrading to 0.32 to workaround this temporarily.

specific regression

0.33.0 changed the resolution logic slightly in #365 to fix a variety of issues when integrating with other plugins (such as Svelte in particular).

It seems like this regression popped up as a result of that. I think I'll need to add an early return after the filter on this line to handle this.
I think that should fix this issue while maintaining #365's fix, though may need to add some testing for this edge case.

Thanks for reporting this as it turns out to be due to a regression!

@agilgur5 agilgur5 added solution: workaround available There is a workaround available for this issue scope: integration Related to an integration, not necessarily to core (but could influence core) kind: regression Specific type of bug -- past behavior that worked is now broken solution: needs test This issue requires creating a test to assuredly close out labels Sep 26, 2022
@FranklinWhale
Copy link

I think this may be related to an issue in plugin-node-resolve 14.x: rollup/plugins#1267

@agilgur5
Copy link
Collaborator

@FranklinWhale that could impact some things, but that doesn't seem to be related to this specific issue. Downgrading node-resolve in the repro does not fix the issue.

And, in general, rpt2 should be filtering in its resolveId hook as well. The ordering of plugins then wouldn't matter for this case, since rpt2 would skip this resolution anyway.

@agilgur5
Copy link
Collaborator

agilgur5 commented Oct 4, 2022

This has been fixed in #428 and released in 0.34.1.

I also confirmed in the repro that this issue no longer occurs when using 0.34.1.

Uskrai added a commit to Uskrai/mado that referenced this issue Oct 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Something isn't working properly kind: regression Specific type of bug -- past behavior that worked is now broken scope: integration Related to an integration, not necessarily to core (but could influence core) solution: needs test This issue requires creating a test to assuredly close out solution: workaround available There is a workaround available for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants