{"id":13224,"library":"geostyler-wfs-parser","title":"GeoStyler WFS Parser","description":"GeoStyler WFS Parser is an npm package that provides a robust implementation of a GeoStyler Data Parser specifically designed for interacting with Web Feature Services (WFS). Currently at stable version 3.0.1, the library sees active development with recent releases, including major updates in July 2024. Its primary function is to read and interpret data from WFS endpoints, converting it into a GeoStyler-compatible data structure for further styling and manipulation within the GeoStyler ecosystem. A key differentiator is its tight integration into the GeoStyler project, offering a standardized approach to WFS data consumption. Users should note that for successful operation, the target WFS service must support `application/json` as an output format, and its application server needs to be configured to send CORS headers if the WFS service is hosted on a different origin than the consuming application. The package ships with TypeScript types, facilitating robust development.","status":"active","version":"3.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/geostyler/geostyler-wfs-parser","tags":["javascript","geostyler","parser","data","wfs","typescript"],"install":[{"cmd":"npm install geostyler-wfs-parser","lang":"bash","label":"npm"},{"cmd":"yarn add geostyler-wfs-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add geostyler-wfs-parser","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Since v3.0.0, the package is ESM-only. CommonJS `require()` is no longer supported.","wrong":"const WfsParser = require('geostyler-wfs-parser');","symbol":"WfsParser","correct":"import { WfsParser } from 'geostyler-wfs-parser';"},{"note":"While named imports are preferred, direct path imports might be used in specific bundler configurations prior to v3.0.0. Since v3.0.0, the main export path is recommended.","symbol":"WfsParser","correct":"import WfsParser from 'geostyler-wfs-parser/dist/WfsParser';"},{"note":"While not directly from `geostyler-wfs-parser`, the `Data` type from the core `geostyler` package is commonly used when interacting with the parser's output for type safety.","symbol":"Data","correct":"import { Data } from 'geostyler';"}],"quickstart":{"code":"import { WfsParser } from 'geostyler-wfs-parser';\nimport { Data } from 'geostyler'; // Import GeoStyler Data type for type safety\n\nasync function parseWfsData(): Promise<void> {\n  const wfsParser = new WfsParser();\n  // Replace with a valid WFS GetCapabilities URL that supports application/json output\n  const wfsUrl = process.env.WFS_SERVICE_URL ?? 'https://your-wfs-server.com/geoserver/wfs'; \n\n  try {\n    // The `read` method fetches and parses WFS data.\n    // `requestParams` is required since v2.0.0 to specify WFS parameters.\n    const { data }: { data: Data } = await wfsParser.read(wfsUrl, {\n      requestParams: {\n        version: '1.1.0', // Specify WFS version\n        typeName: 'feature:my_layer', // Replace with your target layer's typeName\n        outputFormat: 'application/json' // Essential for this parser\n      }\n    });\n    console.log('Successfully parsed WFS Data:');\n    console.log(JSON.stringify(data, null, 2));\n    // 'data' now contains GeoStyler-compatible feature data\n\n  } catch (error) {\n    console.error('Failed to parse WFS data:', error instanceof Error ? error.message : error);\n  }\n}\n\nparseWfsData();","lang":"typescript","description":"This quickstart demonstrates how to instantiate the WfsParser and use its `read` method to fetch and parse data from a WFS service, logging the resulting GeoStyler-compatible data object. It highlights the use of `requestParams` and the necessity of `application/json` output."},"warnings":[{"fix":"Migrate your project to use ES modules (`import ... from '...'`) instead of CommonJS `require()`. Adjust your bundler configuration to correctly resolve ESM dependencies.","message":"Version 3.0.0 switched to an ESM-only build. Projects using CommonJS `require()` will need to migrate to `import` statements and may require bundler configuration adjustments (e.g., for Webpack, Vite).","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Update calls to the `read` method. Instead of `parser.read(url, version, typeName)`, use `parser.read(url, { requestParams: { version, typeName } })`.","message":"Version 2.0.0 introduced the `requestParams` object. All request-related arguments (like `version`, `typeName`, `maxFeatures`) previously passed directly to the `read` method were moved into this nested object.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Ensure your WFS service is configured to provide JSON output. If not, the parser will fail to interpret the response. You might need to adjust the `outputFormat` in `requestParams` if the service supports other JSON variants.","message":"The `geostyler-wfs-parser` library requires the target WFS service to support `application/json` as an output format for its GetFeature or DescribeFeatureType requests.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If encountering network errors related to cross-origin access, contact the administrator of the WFS service to ensure it has CORS enabled for your client's origin. Alternatively, consider proxying the WFS requests through your own backend.","message":"When consuming a WFS service from a different origin (domain, protocol, port) than your application, the WFS application server must be configured to send appropriate CORS (Cross-Origin Resource Sharing) headers.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change `const WfsParser = require('geostyler-wfs-parser');` to `import { WfsParser } from 'geostyler-wfs-parser';`. Ensure your project's `package.json` has `\"type\": \"module\"` or that your build system is configured for ESM.","cause":"Attempting to import `geostyler-wfs-parser` using CommonJS `require()` syntax in a Node.js or bundler environment after v3.0.0.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module ... not supported."},{"fix":"Refactor your `read` method call. Instead of `parser.read(url, { version: '1.1.0' })`, use `parser.read(url, { requestParams: { version: '1.1.0' } })`.","cause":"Calling the `read` method after v2.0.0 without wrapping request parameters in the `requestParams` object.","error":"TypeError: Cannot read properties of undefined (reading 'version') at WfsParser.read"},{"fix":"Verify that the WFS service's server is configured to include `Access-Control-Allow-Origin` headers that permit requests from your application's origin. Alternatively, use a proxy server to forward requests.","cause":"A common browser error indicating a CORS policy block when the WFS service is on a different origin without proper CORS headers.","error":"Error: Network request failed, status 0"},{"fix":"Ensure the `outputFormat` in your `requestParams` is correctly set to `application/json` and that the WFS service truly supports this format. Check the network tab in your browser's developer tools for the actual response from the WFS server.","cause":"The WFS service returned an XML error message or an unsupported format instead of `application/json` as expected.","error":"Error: Failed to parse WFS data: Unexpected token '<', \"<ows:Exception\" is not valid JSON"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}