question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Importing ol/style into component

See original GitHub issue

Hello!

In a Nuxt project, I’m using vl-layer-vector, and I need to style the features in the component based on some other data that I import from Wikidata.

This example by @ghettovoice shows clearly how to do it, however, because OpenLayers is included from CDN, you can call ol.style.Style().

But if I want to import Style, Fill, or Stroke into my component’s <script> section usingimport Style from 'ol/style/Style', I get Cannot use import statement outside a module.

This has been brought up in https://github.com/ghettovoice/vuelayers/issues/382 and https://github.com/ghettovoice/vuelayers/issues/281, but there was no clear solution suggested.

I’m happy to contribute the solution to the docs once it’s clarified.

Thanks for the great work 😃

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ghettovoicecommented, Jul 9, 2021

I don’t actually understand what a reason of this error. I have made a short investigation of it and found this issue https://github.com/zloirock/core-js/issues/743. And I found that switching of useBuiltIns : “usage” to “entry” is really helps.

Here is my test app https://github.com/ghettovoice/vl-ol-nuxt-test-app. I have setup it with create-nuxt-app package. Then:

  1. add 2 plugins: ~/plugins/ol.js and ~/plugins/vuelayers.js https://github.com/ghettovoice/vl-ol-nuxt-test-app/tree/main/plugins
  2. adjust nuxt js config at plugins, modules and build keys https://github.com/ghettovoice/vl-ol-nuxt-test-app/blob/main/nuxt.config.js
  3. change default view compoent https://github.com/ghettovoice/vl-ol-nuxt-test-app/blob/main/components/Tutorial.vue.

And it seems working without errors.

1reaction
ghettovoicecommented, Jul 4, 2021

Hello @majdal , did you tried setup vuelayers and openlayers inside nuxt as plugin? https://vuelayers.github.io/#/docs/quickstart?id=nuxtjs

UPD also take a note that ol package exports ES6 modules, so probably you also need to try this https://nuxtjs.org/docs/2.x/directory-structure/plugins#es6-plugins

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to import a CSS file in a React Component - Stack Overflow
C:\Users\User\Documents\pizza-app\client\public\styles\disabledLink.css is the location of the CSS file I'm trying to load. To me it seems like ...
Read more >
4 Ways to add Styles to React Component | by Mayank Gupta
4 Ways to add Styles to React Component · 1. Adding Global Style to “index.html” · 2. Inline Style in React Component ·...
Read more >
Adding a Stylesheet | Create React App
React, { Component } from 'react'; · import './Button.css'; // Tell webpack that Button.js uses these styles · class Button extends Component {...
Read more >
How To Use Styled-Components In React - Smashing Magazine
We do not have to create two styled components for them; we can adapt their styling based on their props. import styled from...
Read more >
Different Ways to Write CSS in React
Create a new CSS file in your project directory. Write CSS. Import it into the React file. Like this: import "./style.css" ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found