jshttp / cookie

HTTP server cookie parsing and serialization
MIT License
1.36k stars 159 forks source link

Can't use as ES Module in Babel project in cookie==1.0.1 #203

Closed SeanHayes closed 3 weeks ago

SeanHayes commented 3 weeks ago

When I use import cookie from 'cookie'; in my babel project, when I call cookie.parse('some string') I get: TypeError: Cannot read properties of undefined (reading 'parse')`

Any tips for getting this to work? Here's my babel.config.js:

module.exports = function (api) {
    api.cache(true);

    return {
        "presets": [
            [
                "@babel/preset-env",
                {
                    "useBuiltIns": "entry",
                    "targets": {
                        "node": "current"
                    },
                    "ignoreBrowserslistConfig": true
                }
            ]
        ],
        "ignore": [],
        "plugins": [
            ["babel-plugin-transform-import-meta"],
            ["module-resolver", {
              "root": ["./src/**"],
              "alias": {
                "~": "./",
              }
            }],
            [
                "@babel/plugin-transform-runtime",
                {
                    "corejs": false,
                    "helpers": true,
                    "regenerator": true
                }
            ],
            "inferno",
            ["@babel/plugin-proposal-decorators", {
                "version": "legacy"
            }],
            [
                "babel-plugin-inline-import",
                {
                    "extensions": [
                        ".csv",
                        ".txt"
                    ]
                }
            ],
            ["inline-json-import", {}],
            [
                "babel-plugin-transform-require-ignore",
                {
                    "extensions": [
                        ".css",
                        ".scss",
                        ".worker.js"
                    ]
                }
            ],
            "dynamic-import-node"
        ]
    };
}
blakeembrey commented 3 weeks ago

Please see how to import it in the README. Duplicate of https://github.com/jshttp/cookie/issues/195.