beaugunderson/ip-address

Uncaught ReferenceError: exports is not defined

Closed this issue · 7 comments

Hello,

I feel that this is a very basic issue due to my unfamiliarity with Typescript and the use of larger javascript libraries.

I've built the library from version 10.0.1 and I'm trying to use it in my Flask webapp.

I'm importing ip-address.js and when loading the page, I get this in my console:

Uncaught ReferenceError: exports is not defined
    <anonymous> http://127.0.0.1:5000/static/js/ip-address.js:21

I must be importing the wrong file to use this library, but I searched the rest of the Javascript files that I built with tsc and I am unable to find where exports is actually defined. I've also tried importing common.js, but I get the same reference error about exports not being defined.

A "quick start" type guide to using this library would be wonderful to help users who are less familiar with frontend development get started with this library. I've seen https://ip-address.js.org/ but it looks like this only contains API reference material.

So, how do I use this library?

Thanks for the super quick response, Beau!

Unfortunately the project is not open source - it's for an internal tool I'm building for work. I am not using a bundler - I just built with tsc and copied the resulting JS files (and structure) from dist/ into my Flask project. Here's the resulting files and directory structure of the ip-address library within my Flask project:

~/python-projects/vxlan-automation/flask-app/src/static/js/ip-address$ tree .
.
├── address-error.d.ts
├── address-error.d.ts.map
├── address-error.js
├── address-error.js.map
├── common.d.ts
├── common.d.ts.map
├── common.js
├── common.js.map
├── ip-address.d.ts
├── ip-address.d.ts.map
├── ip-address.js
├── ip-address.js.map
├── ipv4.d.ts
├── ipv4.d.ts.map
├── ipv4.js
├── ipv4.js.map
├── ipv6.d.ts
├── ipv6.d.ts.map
├── ipv6.js
├── ipv6.js.map
├── v4
│   ├── constants.d.ts
│   ├── constants.d.ts.map
│   ├── constants.js
│   └── constants.js.map
└── v6
    ├── constants.d.ts
    ├── constants.d.ts.map
    ├── constants.js
    ├── constants.js.map
    ├── helpers.d.ts
    ├── helpers.d.ts.map
    ├── helpers.js
    ├── helpers.js.map
    ├── regular-expressions.d.ts
    ├── regular-expressions.d.ts.map
    ├── regular-expressions.js
    └── regular-expressions.js.map

2 directories, 36 files

...and I've tried importing ip-address.js, common.js, and ipv4.js from the top-level ip-address directory.

Yes - here it is below (I didn't make any changes to it so it should be identical to the one included in the current master branch)

{
  "compilerOptions": {
    "target": "es2016",
    "module": "commonjs",
    "allowJs": true,
    "declaration": true,
    "declarationMap": true,
    "rootDir": "./src",
    "outDir": "./dist",
    "resolveJsonModule": true,
    "sourceMap": true,

    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictBindCallApply": true,
    "strictPropertyInitialization": true,
    "noImplicitThis": true,
    "alwaysStrict": true,

    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,

    "esModuleInterop": true,

    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,

    "lib": ["es2020"]
  },

  "include": [
    "./src/**/*.ts"
  ]
}

Edit: And here's how I built it after cloning:

git clone https://github.com/beaugunderson/ip-address.git
cd ip-address/
ls
tsc
sudo apt install node-typescript
tsc
cp -r dist/* ../../static/js/ip-address/

I'm not too sure how to implement that. I'll just handle the IP address parsing on the backend. Thank you for your assistance.