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

@open-wc/webpack-import-meta-loader: Cannot read properties of undefined (reading 'length') #6

Open
dcolley opened this issue Apr 27, 2022 · 1 comment

Comments

@dcolley
Copy link

dcolley commented Apr 27, 2022

Expected behavior

On Vue2, including the @open-wc/webpack-import-meta-loader as follows

vue create test-app
cd test-app
npm install --save @polkadot/api @open-wc/webpack-import-meta-loader

Configure vue.config.js

module.exports = {
	configureWebpack: {
		module: {
			rules: [
				{
					test: /\.js$/,
					loader: require.resolve('@open-wc/webpack-import-meta-loader'),
				},
			]
		}
	},	
}

in src/App.vue

import HelloWorld from './components/HelloWorld.vue'
import api from '@polkadot/api'
export default {
  name: 'App',
  components: {
    HelloWorld
  },
  created() {
    console.debug(api)
  },
}

Build the project

npm run build

Actual Behavior

I added a debug into node_modules/@open-wc/webpack-import-meta-loader.js
Line 19: console.log("webpack-import-meta-loader.js: rootContext", this.rootContext)

npm run build

> [email protected] build
> vue-cli-service build


⠴  Building for production...webpack-import-meta-loader.js: rootContext /Users/derek/Sites/test-app
webpack-import-meta-loader.js: rootContext /Users/derek/Sites/test-app
⠧  Building for production...webpack-import-meta-loader.js: rootContext undefined


 ERROR  Failed to compile with 1 error                                                                                           16:44:26

Syntax Error: Thread Loader (Worker 0)
Cannot read properties of undefined (reading 'length')


You may use special comments to disable some warnings.
Use // eslint-disable-next-line to ignore the next line.
Use /* eslint-disable */ to ignore all warnings in a file.
 ERROR  Build failed with errors.

Additional context

I found when this.rootContext is undefined, this.options.context was populated... ?!

  if(!this.rootContext) {
    // console.log("webpack-import-meta-loader.js: this.options.context", this.options?.context)
    // console.log("webpack-import-meta-loader.js: rootContext", this.rootContext)  
    console.log("webpack-import-meta-loader.js: resource", this.resource)  
    // console.log(source)
    this.rootContext = this.options.context
  }
  var ctx = this.rootContext ? this.rootContext : this.options.context
  const relativePath = this.context.substring(
    // this.context.indexOf(this.rootContext) + this.rootContext.length + 1,
    this.context.indexOf(ctx) + ctx.length + 1,
    this.resource.lastIndexOf(path.sep) + 1,
  );

I don't know if this 'hack' is appropriate, but it stops the error... :/

@Westbrook
Copy link

We've not actively maintained this package for quite some time. See it in our "legacy" repo: https://github.com/open-wc/legacy/tree/master/packages/webpack-import-meta-loader

If you happened to find a fix that you felt made sense, feel free to open a PR, but we are not investing work in the package at this time.

@web-padawan web-padawan transferred this issue from open-wc/open-wc Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants